[Tutor] Re: Help in geting external program output

Abel Daniel abli at freemail.hu
Mon Aug 25 16:55:30 EDT 2003


"Wael Salloum" wrote:

> So I am just learning python- and I have a program in java
> and it writes into a file, and I want it to return the filename to me
> (in python.)
> So I have a script and I use fileName = os.popen(`java
> theApplication').read()
> However, its always returning blank!
> Now when I do os.popen(`dir').read() it works just fine...
>
> So my question is, what does Python deem is the output of
> a file, and how can I get my java code to `output' a filename..
With os.popen you get a pipe connected to the program you launched.
This means that you can write to it's stdin and read from it's stdout.
(and maybe stderr, I'm not that familiar with os.popen.)

Essentially, you can do the same thing a user could when launching the
program from console, i.e. a dos shell. If you execute
'java theApplication' from a dos shell, and the filename isn't written
back, then you won't be able to read it with os.popen, either.

The most likely problem is that your java program isn't writing to
stdout.

I don't know much about java, but a quick googling showed this as an
example for writing to stdout:
-----
// http://www.bagley.org/~doug/shootout/

public class hello {
    public static void main(String args[]) {
    System.out.print("hello world\n");
    }
}
-----

-- 
Abel Daniel

ps. sending html mail to a mailing list is a really bad idea.



More information about the Tutor mailing list