Ask Your Question

Revision history [back]

I often use os.popen to solve exactly this problem:

sage: os.popen('pwd').read()

Big Caveat: Note that according to the Python docs, os.popen is deprecated and one is supposed to use subprocess.Popen as explained here. However, if you look at the examples using subprocess.Popen to do the same as what you can do using os.popen, you see that using subprocess.Popen makes the code often twice as long and complicated. This sucks. I think it would be good to add a new command to Sage that works much like'...').read(), and is implemented using subprocess. I don't think this currently exists.