[Tutor] Finding error from os.system(cmd)
Steven D'Aprano
steve at pearwood.info
Tue May 31 00:38:28 CEST 2011
Kann Vearasilp wrote:
> 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
Define "not working properly".
My guess is that you're probably getting an exception
OSError: [Errno 2] No such file or directory
before os.system is even called. For the code you give to even have a
hope of working correctly, you need to call it from the current
directory containing:
current directory:
tmp/medusa
mirnaworkbench/Medusa/Medusa.jar
otherwise abspath will fail and os.system will not even be called.
> executing 'java' from terminal worked just fine. I am not sure what is
> wrong here.
In the Python code you give, you don't just execute "java", you execute
a fairly complex command line. What happens when you execute that
*exact* same line from the terminal, not just "java"?
> Is there a way to print out/detect error in my code for
> this case?
os.system(cmd) will print any output to the terminal, just as if you ran
it from the terminal yourself. Open a Python interactive interpreter,
and run os.system(cmd) at the prompt, and read the output.
--
Steven
More information about the Tutor
mailing list