António Rocha wrote:

> Greetings
> 
> In a Python script I'm using this to run an external BIN:
> p=subprocess.call(command) where command is my command to run the bin. p 
> will be equal tot he return values of the bin.
> (so far so good)
> But I'm getting an error now while running bin:
>  File "C:/EIS/scripts/mycopy", line 577, in
> <module>
>    main()
>  File "C:/EIS/scripts/mycopy", line 278, in main
>    p=subprocess.call(command)
>  File "C:\EIS\Python25\lib\subprocess.py", line 444, in
> call
>    return Popen(*popenargs, **kwargs).wait()
>  File "C:\EIS\Python25\lib\subprocess.py", line 594, in
> __init__
>    errread, errwrite)
>  File "C:\EIS\Python25\lib\subprocess.py", line 816, in
> _execute_child
>    startupinfo)
> WindowsError: [Error 193]
> 
> My problem is not the error but, is there a way to "get" the error and 
> stop the process in a more smoother way instead of stopping so drastically?

According to MSDN:

        http://msdn.microsoft.com/en-us/library/ms681382%28v=vs.85%29.aspx

        ERROR_BAD_EXE_FORMAT    %1 is not a valid Win32 application.
        193 (0xC1) 

Note that if you want to run something other than a binary executable,
you have to use pass shell=True to subprocess.call.

As for catching the exception, use e.g.:

        try:
            p = subprocess.call(...)
            ...
        except OSError, e:
            # deal with exception

WindowsError is a subclass of OSError; catching OSError will be more
portable. If you need to catch "all" errors, use StandardError, which
is the base class of "real" errors (it doesn't include non-error
exceptions such as Warning, StopIteration, SystemExit, etc).

-- 
Glynn Clements <[email protected]>
_______________________________________________
grass-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-dev

Reply via email to