0

I have a scenario where I want to open the command prompt while execute the following method -

public static int executeScript(){
    String scriptPath = "C:\\test"
    String command = "cmd /c start  "+scriptPath+"\\backup.bat > "+scriptPath+"\\Logs.txt";
    Process process = Runtime.getRuntime().exec(command);
    return process.waitFor();
}

User wants to see the command prompt when the testRun.bat executes. When we deploy the application from command prompt it is running as expected user see the command prompt of the backup script execution. But In the production environment the application runs as window service, In this case the command prompt is not visible.

How can I show the command prompt when application is running as window's service?

thanks in advance.

Rakesh Chouhan
  • 1,196
  • 12
  • 28
  • What happens if you try something like `Runtime.getRuntime().exec("cmd /c start cmd /k echo test");`? I haven't done much with windows services, but that may launch the command prompt (it should leave cmd open at the end, can swap /k with /c after) – phflack Oct 25 '17 at 14:39
  • The script logs are empty, and I am unable to see the command prompt. – Rakesh Chouhan Oct 25 '17 at 14:43
  • 1
    For security reasons, services run non-interactively by default so they can't directly interact with the user which includes showing a console. What you could do instead is create a secondary GUI process in the user session and send the output of your batch file to that process which would show it in the GUI. See also: [Interactive Services](https://msdn.microsoft.com/en-us/library/windows/desktop/ms683502(v=vs.85).aspx) – zett42 Oct 25 '17 at 14:43
  • Thanks @zett42 ! I solved this issue in different way I used processBuilder to invoke the script and shown the message on UI after script execution done. – Rakesh Chouhan Oct 26 '17 at 12:12

0 Answers0