I have a shell script test.sh that does:
cat /home/tomcat/temp/tempLogFile.log > /home/tomcat/temp/logFile_test.log
I call test.sh from java by Runtime.getRuntime().exec("test.sh")
It creates the logFile_test.log but nothing written to it.
If I run the script directly from shell, it works fine. What could be going wrong?
Thanks,
UPDATE: Interstingly, it works fine if I do
echo 'cat /home/tomcat/temp/tempLogFile.log > /home/tomcat/temp/logFile_test.log' | at now
But I cant use at now
since I need to wait for cat to finish
Maybe your command path is messed up? That command will create logFile_test.log even if it can't run the cat
program. Try adding something like:
set > /tmp/dump.txt
to the shell script. This will write a copy of the process's environment variables to /tmp/dump.txt
. Inspecting those might help you figure out the problem.
Another possibility is that the disk is full. In that case, you'd be able to create empty files, but not write any data to them.
Once you invoke the getRuntime().exec("ANY_COMMAND");
, it returns you an instance of Process, using process object you can get Input and Output Streams and then pass any other command to the same process or read the output , for that purpose you have three streams connected
even if you have any errors, you can check the error stream and see whats going wrong.
you may refer Java process.getInputStream() has nothing to read, deadlocks child
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.