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

Kann Vearasilp vearasilp at gmail.com
Tue May 31 11:41:13 CEST 2011


Hi All,

I apologize for now being specific enough. The testing environment was
actually "django ver. 1.2" which is a CMS based on python codes; so, I
figured it's python related and want to post my question here as well.

Anyway, Here is a more detail about what I have facing now. The java
script should read files in "tmp/medusa" and use "Medusa.jar" as the
referenced classes to run. The result of the script should be a png
image using data from files inside "tmp/medusa"

I tested the complete java command via terminal and it worked fine.
The PNG image was created correctly.

I tested the python package using python shell by importing the
package. (It is called MedusaConnector) So, I run the
"MedusaConnector.create_image()", and the PNG image was created
properly as well. So, I think this showed that the os.path.abspath()
could find both directory and the jar file.

Therefore, I imported the MedusaConnector package into views.py, a
place where you should place all your python codes in a view, and try
to run it using django internal webserver. This time, the PNG file was
created, but with and empty image unlike those from 2 previous test
cases. To notice that the image file was also created, I guess that
the java command must have seen both directory and jar file also.
However, something was wrong there which made the java script to
produce the empty PNG image instead. So, now I am trying to track down
and figure out what went wrong with my code.

java command worked ok on command line. So, I guess it's the issue
with python. I hope it's python. My worst case scenario would be that
the error is with the java not python, and I really have no idea about
java programming...

Kann

Really have no idea what's going on here...

Kann

On Tue, May 31, 2011 at 12:38 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> 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
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list