A******a 发帖数: 61 | 1 Process p = Runtime.getRuntime("cat /users/test/file1.txt /users/test/file2.
txt > /users/test/file3.txt").exec;
It reports an error like this:
cat: /users/test/file3.txt: No such file or directory
it seems it is the redirecting ">" symbol makes problem.
can anyone help here?! thanks. |
g*****g 发帖数: 34805 | 2 The trick is to use a script to put down your command,
then use java to call that script.
file2.
【在 A******a 的大作中提到】 : Process p = Runtime.getRuntime("cat /users/test/file1.txt /users/test/file2. : txt > /users/test/file3.txt").exec; : It reports an error like this: : cat: /users/test/file3.txt: No such file or directory : it seems it is the redirecting ">" symbol makes problem. : can anyone help here?! thanks.
|
Z****e 发帖数: 2999 | 3 or use getOutputStream of Process class if more control is desired, but that
generally requires writing a thread to read the output
【在 g*****g 的大作中提到】 : The trick is to use a script to put down your command, : then use java to call that script. : : file2.
|
z***h 发帖数: 405 | 4 should it be
Runtime.getRuntime().exec("cat ... ");
?
file2.
【在 A******a 的大作中提到】 : Process p = Runtime.getRuntime("cat /users/test/file1.txt /users/test/file2. : txt > /users/test/file3.txt").exec; : It reports an error like this: : cat: /users/test/file3.txt: No such file or directory : it seems it is the redirecting ">" symbol makes problem. : can anyone help here?! thanks.
|
A******a 发帖数: 61 | 5 Thanks! yes, that is one solution. another one is here, need to write the
command as a string array and tell the shell dir clearly:
http://www.unix.com.ua/orelly/java-ent/servlet/ch13_04.htm
"
String[] command = { "/bin/csh", "-c", "finger | grep -v jhunter" };
The program Java executes is /bin/csh. csh is passed two arguments: -c,
which asks the shell to execute the next parameter, and finger | grep -v
jhunter, which is executed by the shell."
【在 g*****g 的大作中提到】 : The trick is to use a script to put down your command, : then use java to call that script. : : file2.
|