Re: exec problem is JDK 1.7.0_21
On 4/21/2013 6:30 AM, Chris Uppal wrote:
Nothing like experiment :-) But two questions: what version of windows were
you using ? And what kind of external application were you testing it with ?
-- chris
I haven't followed this thread closely enough to really understand the
controversy. But I like experiments. And I never get to write anything
in C any more.
Windows XP (the results on Xubuntu 12.10 are identical)
One quoted argument "hello world"
C:\Documents and Settings\Knute Johnson>java test
argc=2
argv[0]=C:\Documents and Settings\Knute Johnson\test.exe
argv[1]=hello world
exitValue=123
Two arguments
C:\Documents and Settings\Knute Johnson>java test
argc=3
argv[0]=C:\Documents and Settings\Knute Johnson\test.exe
argv[1]=hello
argv[2]=world
exitValue=123
---
#include <stdio.h>
int main(int argc, char** argv) {
int i = 0;
printf("argc=%d\n",argc);
for (i=0; i<argc; i++)
printf("argv[%d]=%s\n",i,argv[i]);
return 123;
}
---
import java.io.*;
public class test {
public static void main(String[] args) throws Exception {
ProcessBuilder pb = new ProcessBuilder("test.exe","hello world");
// ProcessBuilder pb = new
ProcessBuilder("test.exe","hello","world");
pb.redirectError(new File("error"));
Process p = pb.start();
final InputStream is = p.getInputStream();
Thread t = new Thread(new Runnable() {
public void run() {
int n;
try {
while ((n = is.read()) != -1)
System.out.print((char)n);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
});
t.start();
t.join();
System.out.println("exitValue=" + p.exitValue());
}
}
--
Knute Johnson