Posted By:
Simon_Ablett
Posted On:
Thursday, June 5, 2003 03:48 AM
I would say that the reason you are not seeing anything is to do with your stdout / stderr streams getting redirected (i.e. to the bash shell). If you change your code to something akin to the following.
public class T
{
public static void main(String args[]) throws Exception
{
String[] cmd = {"/bin/bash", "-c", "echo Simon > ./log.log"};
Runtime.getRuntime().exec(cmd);
}
}
Then you will see that, assuming that the access rights are correct, a file called 'log.log' has been created conatining the string 'simon'. This implies that the commands are being run correctly. Now try the following.
public class T
{
public static void main(String args[]) throws Exception
{
String[] cmd = {"/bin/bash", "-c", "/bin/ls > ./log.log"};
Runtime.getRuntime().exec(cmd);
}
}
Now the file contains the results of your 'ls' operation.
Regards.