0

I am newbie for calling scripts from Java through the SFTP connection.

So far, I managed to find the code snippets below

Process p  = Runtime.getRuntime().exec("cmd /c start Hello.bat");
p.waitFor();

Here is sample for Hello.bat

@echo off
echo "Hello World"

However, I couldn't see the output in cmd window eve there were no errors.(seem like Hello.bat file location is not right?)

My actual and final script include copying, reading, archiving, delete and return code for success or fail.

What type of script with the above methods will be fine and I hope some one will advise me for the right direction with working sample.

Thanks and best regards

Konstantin Yovkov
  • 62,134
  • 8
  • 100
  • 147
Kyaw
  • 1

1 Answers1

0

just Runtime.getRuntime().exec("cmd /c start Hello.bat") works for me. Also see How do I run a batch file from my Java Application?

Make a small change in batch file to keep command prompt open

@echo off
echo "Hello World"
PAUSE

so your java code is fine you just need to modify batch file to keep command prompt open when program is run successfully.

Community
  • 1
  • 1
M Sach
  • 33,416
  • 76
  • 221
  • 314