No announcement yet.

Running Dos Shell Command

  • Filter
  • Time
  • Show
Clear All
new posts

  • Running Dos Shell Command

    I try to run this shell command and nothing happens:

    java.lang.Runtime.getRuntime().exec("cmd.exe /c C:\\Temp\\test.bat");

    No errors show on the channel or in the Dashboard log (Running on Windows Server 2003). If I run the batch file manually it works fine. I looked at the 5 other posts having to do with running shell commands and I don't see that anyone has gotten this working. Please advise.

    For excrements and giggles I have also tried:

    java.lang.Runtime.getRuntime().exec("cmd.exe /c C:/Temp/test.bat");
    java.lang.Runtime.getRuntime().exec("C:\\Temp\\tes t.bat");
    java.lang.Runtime.getRuntime().exec("call C:\\Temp\\test.bat");
    java.lang.Runtime.getRuntime().exec("call C:/Temp/test.bat");
    Last edited by grimm_jason; 04-18-2011, 10:03 AM.

  • #2
    As a slight update, I am able to shell out to run exe files like this line here:

    java.lang.Runtime.getRuntime().exec("C:\\Program Files\\PGPcmdln\\PGP.exe -e " + file_path + "Reports_" + Year + Month + Day + ".zip " + '"Test"');

    But shelling out to call a batch file with cmd.exe still produces nothing. I figure it isn't liking some syntax in DOS, but the error doesn't come back through java. I am thinking of running the same command and redirecting output 1&2> batch.log or something. If there is a dos error I am not seeing maybe that would work?


    • #3
      Adding ">> batch.log 1>&2" to the end of the command worked. This can be used to call batch files shelling out to DOS. It kinda makes sense because where is the stdout and stderror gonna go unless you redirect it. Thx everyone for all the help .............