Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Capturing stdout from a class method

Reply
Thread Tools

Capturing stdout from a class method

 
 
Falcolas
Guest
Posts: n/a
 
      06-27-2007
I have a rather strange situation, and I'm not sure my brief
experience of Python will let me handle it properly.

The situation is this: I have a Java class "X" which I need to call in
a Jython script. The output of "X" is sent to stdout using the java
call System.out. I need to capture this output, and preform tests on
it in the Jython script.

My first pass at a design involves two jython scripts. One (we'll call
it "Y") whose sole function is to instantiate and call "X", and die.
The second script will call "Y" using a method which captures stdout
to a pipe. The second script would then read the stdout from the pipe
and act accordingly.

Can anybody suggest a better way to handle this? The Java class, "X",
can not be modified for this test.

 
Reply With Quote
 
 
 
 
Thomas Jollans
Guest
Posts: n/a
 
      06-27-2007
Falcolas wrote:
> I have a rather strange situation, and I'm not sure my brief
> experience of Python will let me handle it properly.
>
> The situation is this: I have a Java class "X" which I need to call in
> a Jython script. The output of "X" is sent to stdout using the java
> call System.out. I need to capture this output, and preform tests on
> it in the Jython script.
>
> My first pass at a design involves two jython scripts. One (we'll call
> it "Y") whose sole function is to instantiate and call "X", and die.
> The second script will call "Y" using a method which captures stdout
> to a pipe. The second script would then read the stdout from the pipe
> and act accordingly.
>
> Can anybody suggest a better way to handle this? The Java class, "X",
> can not be modified for this test.


How about subprocess.Popen ? I'm thinking of something like this:

import subprocess

X_proc = subprocess.Popen(['java', 'Xstarter'])
for line in Xproc.stdout:
# do funky stuff
pass




-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGgr8lJpinDvQhQ0sRAjyMAJwJyAxe8odd8z7rDSt2T6 0G0j1ELwCeKCL6
LstzYFWFalmBPrTKfUB6nFI=
=/N6M
-----END PGP SIGNATURE-----

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Capturing stdout from shell script Nigel Wade Java 8 03-18-2011 11:42 PM
Capturing stderr and stdout of a subprocess as a single stream Fuzzyman Python 3 01-07-2007 08:44 PM
Capturing stdout without waiting for the process end Luigi Python 5 04-03-2006 07:24 PM
capturing stdout from lynx.. sergio@village-buzz.com Python 2 03-13-2006 03:07 PM
Capturing stdout incrementally Moosebumps Python 5 04-07-2004 03:38 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57