Re: [GRASS-dev] Catching an issue from external binary using grass Python Script

2011-07-29 Thread Glynn Clements

Jenny Turner wrote:

> *Is it possible to get above text ("This application ..." in a variable?*

If it's being written to stdout or stderr, you can capture those by
replacing subprocess.call() with:

p = subprocess.Popen(, stdout=subprocess.PIPE, 
stderr=subprocess.PIPE)
out, err = p.communicate()

out and err will be strings, containing the data written to stdout and
stderr respectively.

-- 
Glynn Clements 
___
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev


Re: [GRASS-dev] Catching an issue from external binary using grass Python Script

2011-07-28 Thread Jenny Turner
You are absolutely right. I made a mistake. I meant
p=subprocess.call()

If you use subprocess.call(), the return value is the return code of
> the child process.
>
> But In this case I obtain this in Command Output window:

>* This application has requested the Runtime to terminate it*>* in an unusual 
>way.*>* Please contact the application's support team for more*>* information.*

*and my p is 3 (don't know why because in no place of the binary there
is any return 3)*

*Is it possible to get above text ("This application ..." in a variable?*

*Thanks*

*Jenny*



> If you use subprocess.Popen(), the .wait() method returns the child
> process' return code, which can also be retrieved from the .returncode
> attribute of the Popen object.
>
> Typically, a return code of zero indicates success while a non-zero
> value indicates failure. On Unix, a negative value indicates that the
> process terminated due to a signal.
>
> Neither call() nor Popen() raise an exception if the spawned program
> "fails" in some sense, only if they are unable to execute the program,
> query its status, etc.
>
> --
> Glynn Clements 
>
___
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

Re: [GRASS-dev] Catching an issue from external binary using grass Python Script

2011-07-28 Thread Glynn Clements

Jenny Turner wrote:

> I have a Grass Python script that calls an external binary using subprocess
> like:
> p=subprocess(). Due to some limitations (memory) sometimes i get
> this copied into Command Output:
> This application has requested the Runtime to terminate it
> in an unusual way.
> Please contact the application's support team for more
> information.
> 
> (this is windows)
> 
> 1- How can catch  this error (with except but I don't know which error to
> use

"p=subprocess()" isn't valid Python; "subprocess" is a
module.

If you use subprocess.call(), the return value is the return code of
the child process.

If you use subprocess.Popen(), the .wait() method returns the child
process' return code, which can also be retrieved from the .returncode
attribute of the Popen object.

Typically, a return code of zero indicates success while a non-zero
value indicates failure. On Unix, a negative value indicates that the
process terminated due to a signal.

Neither call() nor Popen() raise an exception if the spawned program
"fails" in some sense, only if they are unable to execute the program,
query its status, etc.

-- 
Glynn Clements 
___
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev


[GRASS-dev] Catching an issue from external binary using grass Python Script

2011-07-27 Thread Jenny Turner
Greetings

I have a Grass Python script that calls an external binary using subprocess
like:
p=subprocess(). Due to some limitations (memory) sometimes i get
this copied into Command Output:
This application has requested the Runtime to terminate it
in an unusual way.
Please contact the application's support team for more
information.

(this is windows)

1- How can catch  this error (with except but I don't know which error to
use

Thanks
Jenny
___
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev