[Tutor] Finding error from os.system(cmd)

Alexandre Conrad alexandre.conrad at gmail.com
Mon May 30 18:46:04 CEST 2011


Hi Kann,

I haven't looked at your problem closely but you might need to
explicitly tell Python where to output stderr/stdout. I just ran
os.system('ls -al') on my Linux box and it seems to print both
stderr/stdout to my terminal. The return value is the return code of
the process (might be different on another OS though).

As I hint you might want to know that the "subprocess" module is meant
to replace many Python functions that spawn processes, such as
os.system(). The subprocess module might be better documented with
examples:

http://docs.python.org/library/subprocess.html

Only if you are running Python 2.7 (or 3.x I believe), the
subprocess.check_output() function might be useful to you.

HTH,

2011/5/30 Kann Vearasilp <vearasilp at gmail.com>:
> Dear all,
>
> I tried using python to execute some external java program in my code.
> My problem is the os.system(cmd) was not working properly while
> executing 'java' from terminal worked just fine. I am not sure what is
> wrong here. Is there a way to print out/detect error in my code for
> this case?
>
>>>>>
>
>  1 import os
>  2
>  3 def create_image():
>  4     path = os.path.abspath('tmp/medusa')
>  5     medusa = os.path.abspath('mirnaworkbench/Medusa/Medusa.jar')
>  6     cmd = str('java -cp ' + medusa + '
> medusa.batchoperations.BatchOperations ' + path)
>  7     os.system(cmd)
>
>>>>>
>
> Thanks,
>
> Kann
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Alex | twitter.com/alexconrad


More information about the Tutor mailing list