yes. it does clear the file. BUT only when i run from the unix console.
When the same is attempted from a java programme, it fails throwing at the earlier mentioned error.
---------- Post updated at 06:03 PM ---------- Previous update was at 05:53 PM ----------
This error message probably came from the following command:
ksh 'cp /dev/null /t3/envs/dmdev3/test/file_list.txt'
Or even just:
'cp /dev/null /t3/envs/dmdev3/test/file_list.txt'
i.e. It tries to execute a command with the name of all the characters between the single quotes including the space characters.
Just for interest, this would have worked:
Something is going wrong with the quote characters on the ssh command line. I suggest placing the whole command in a Shell script, and then calling that Shell script from java.
It looks like you are trying to execute quoted commands: "cp /dev/null /t3/envs/dmdev3/test/file_list.txt" or ":> /t3/envs/dmdev3/test/file_list.txt" instead of these unquoted ones, eg: : > /dev/null /t3/envs/dmdev3/test/file_list.txt .
i have found out the solution. Though the shell command was right, the way i called it from JAVA caused the issue. The correct java code would be as shown below.
While Googling I came across similar references, but they cross-linked to the old Sun Java site which Oracle in their wisdom have restructured such that old links don't work.
The problem is that the Java exec command tokenizes the command call and places each token onto the system call in order.
Thus:
exec(command)
is the same as
exec(command, null, null)
I'd still place the unix command in a Shell script (complete with appropriate Shebang line) because I can see potential for problems with quote characters and accidentally providing switches to the Shell command.
yeah you are right about the tokenizing part. Also, bash command is requried as the primary parameter while running commands with more than two arguments.
Anyways can you please elaborate your last statement?
PS : Can you please tell me how to close/resolve this thread?