-1

I have a simple servlet program running on apache-tomcat-9.0.38(Windows 10). The program tries to launch command prompt using following code (Not the exact code,)

java.lang.Runtime.getRuntime().exec("cmd.exe /c start cmd.exe /k \"dir && ping \"localhost\" && EXIT\"");

When servlet tries to execute the above line, it does not launch command prompt. However, if I execute the same piece of code in simple java program on same machines, it launches command prompt successfully.

I have verified that the system user and applications have execute access on cmd.exe and also verified that the tomcat service user is system user.

I am not sure why it fails to launch command prompt only when servlet program tries to execute above mentioned line. (Note: Same servlet program works well on other Windows 10 machine )

Quick help will be really appreciated.

Thank you.

Guru
  • 17
  • 1
  • 3

1 Answers1

0

After some analysis, I found a workaround.

As I don't have Administrator access to change Tomcat service's logon user, I have started tomcat manually using command prompt. This worked for me and the code launched the command prompt successfully.

Thank you.

Guru
  • 17
  • 1
  • 3