
Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Hi George
> > I have tried to study the exec calls to see if it is possible to
> > redirect standard io, but so far with no succes. Do you have a
[quoted text clipped - 6 lines]
> You can use shell style redirection (e.g. '>') if you run the command
> in a shell or wrap it in a shell script.
Unfortunately, it seems that I can not. In my first post I stated the
wrong exec-method. In reality I use the one with a String[] as the
first parameter as we could not make the first method work when the
path contains spaces.
> You can try closing the streams at your end. This might cause problems
> for the child when it attempts to write to stdout or stderr, but it
> might not.
This is the path chosen for now - if this gives errors in the other
application we will have to modify it.
> If you can modify the child process, you can make it not produce
> output you aren't interested in.
Even though the output is not really needed on std::cout we use the
console for debugging and convenience. It would be a shame to have to
give it up, but of corse we could have a switch to turn it off when
spawned from Java.
> /gordon
>
> --
> [ do not email me copies of your followups ]
> g o r d o n + n e w s @ b a l d e r 1 3 . s e
Gordon Beaton - 23 May 2006 15:21 GMT
> Hi George
Hello Patrick.
>> You can use shell style redirection (e.g. '>') if you run the command
>> in a shell or wrap it in a shell script.
[quoted text clipped - 3 lines]
> first parameter as we could not make the first method work when the
> path contains spaces.
Yes, you must use exec(String[]) when your command cannot be tokenized
using whitespace.
However I fail to see how that prevents you from using a shell to
redirect the output. On Unix, this works just fine (and I'm certain
there is a similar mechanism for windows):
String[] cmd = {
"/bin/sh",
"-c",
"/path/to/mycommand -o options > /dev/null 2>&1"
};
Process p = Runtime.getRuntime().exec(cmd);
It's even easier with a script:
Process p = Runtime.getRuntime().exec("myscript");
...where the redirection is done within the script.
/gordon

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
peter.koch.larsen@gmail.com - 23 May 2006 22:42 GMT
Gordon Beaton skrev:
> > Hi George
>
> Hello Patrick.
[snip]
> Yes, you must use exec(String[]) when your command cannot be tokenized
> using whitespace.
[quoted text clipped - 8 lines]
> "/path/to/mycommand -o options > /dev/null 2>&1"
> };
Hi Gordon
This is interesting. I presume that the Java exec interface must work
differently from the (C based) interfaces I'm familiar with. I would
have expected the above string to contain two parameters (one of them
containing whitespace and redirection tokens). I'll try that approach
tomorrow.
Thanks again!
Peter
[snip]