The following is the code:

import os
#f=os.popen('date -d @1358193598 +%m/%d/%y')

I tied both ways, and it gave me an error of "broken pipe". Do you happen to know how to deal with this situation? I also tried to use the subprocess module, and it does not work either. The error message is as the following:

Traceback (most recent call last):
  File "t_2.py", line 23, in <module>
  File "t_2.py", line 6, in transfer_date_format
  File "/usr/lib64/python2.6/subprocess.py", line 639, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.6/subprocess.py", line 1228, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

You can try with os.system


Here it will save exit code to the variable f

If you want to take output of executed command to the variable, try

print f
| improve this answer | |
  • "f=os.system" will only run the command, right? what if I'd like to get the output of the command to a string instead? – josephS Jun 27 '17 at 20:26
  • You can take output of executed command using f=os.popen('date').read() – Sourav Jun 27 '17 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.