-1

I want to run a batch file on the server name as xx.xx.xx.xx from my local machine**(yy.yy.yy.yy)**. My batch file is present in c drive in batch folder which is shared but after running a java program it gives error i.e

java.io.IOException: Cannot run program "sas.bat (in directory "\\xx.xx.xx.xx\batch"): CreateProcess error=267, 

The directory name is invalid

at java.lang.ProcessBuilder.start(Unknown Source)".

THANKS in advance.

Java code:

try {


            ProcessBuilder launcher = new ProcessBuilder();
            Map<String, String> environment =launcher.environment();
            launcher.redirectErrorStream(true);

            launcher.directory(new File("\\\\xx.xx.xx.xx\\batch"));
                launcher.command("sas.bat");
            Process p= launcher.start();

                } 
                   catch (Exception e) 
                {

                System.out.println("Execution error");
                e.printStackTrace();
                } 

sas.bat:

"D:\sas home\SASFoundation\9.3\sas.exe" -SYSIN c:\codeexcel.sas
cmd /k
Iamat8
  • 3,888
  • 9
  • 25
  • 35
Pankaj Dagar
  • 87
  • 10
  • Hi is anyone is there to help me out??? – Pankaj Dagar Oct 05 '15 at 05:51
  • May be it's Not able to find the file on server – Pankaj Dagar Oct 05 '15 at 08:31
  • Hello Is anyone is there to help me???? – Pankaj Dagar Oct 05 '15 at 09:40
  • Try `ProcessBuilder launcher = new ProcessBuilder("cmd", "/c", "pushd \\\\xx.xx.xx.xx\\batch & call sas.bat & popd");` and remove `launcher.directory` and `launcher.command`. See also [Start CMD by using ProcessBuilder](http://stackoverflow.com/q/10954194) – wOxxOm Oct 05 '15 at 11:37
  • The program is run successfully but sas.bat does not execute on server.Moreover I have to execute the batch file on server not on local machine.Thanks in Advance. – Pankaj Dagar Oct 05 '15 at 12:21
  • Oh what a surprise! Do you want the batch file to execute on the remote machine? This is a completely different task. Then you should use `psexec` like this: `ProcessBuilder launcher = new ProcessBuilder("psexec", "-u User -p Password cmd /c pushd d:\\batch & call sas.bat & popd");` Edit accordingly `User`, `Password` and `d:\\batch` - this should be the path on the remote machine, not a share name you've been using. – wOxxOm Oct 05 '15 at 12:32
  • This is the 4th question you now have in the past few days related to running bath files from a remote machine. If you spent the time asking a better question (providing more detail) you would probably get better answers. Spamming questions like this is discouraged by the site. Additionally, don't ask for people to help you - it's rude, and probably counter-productive. People will help if they can, and won't if they can't. Don't try and 'bump' threads, and don't bump questions by re-posting them. – Robert Penridge Oct 05 '15 at 20:33
  • Dear wOxxOm I have already tried this("psexec", "-u User -p Password cmd /c pushd d:\\batch & call sas.bat & popd"); earlier and getting- Cannot run program "psexec": CreateProcess error=2, The system cannot find the file specified.One more Information I need provide you is that my local machine having 32 bit OS where remote is of 64 bit. – Pankaj Dagar Oct 06 '15 at 05:28
  • Of course it won't find `psexec` if you don't have it. Download it and install in c:\windows for example. Or somewhere else but then you'll have to provide the full path in ProcessBuilder. BTW is there any reason you don't search before you ask on Google or similar sites? – wOxxOm Oct 06 '15 at 06:37
  • Dear wOxxOm you are continuously helping me in this,I am thankful to you.As per your suggestion this time I have download PSTools.zip and extract in(on my local Machine)-: F:\Softwares\PSTool then I provide the full path in ProcessBuilder as-:ProcessBuilder launcher = new ProcessBuilder("F:\\Softwares\\PSTool\\PsExec", "-u 10.80.10.60 -p xyz@1234 cmd /c pushd c:\\batch & call sas.bat & popd");.Now the program is run successfully but does't execute a sas.bat on server.Is I am missing anything in that? Thanks in advance. – Pankaj Dagar Oct 06 '15 at 07:57
  • Sorry, I haven't used psexec. This is as far as I can help. There must be some way to debug what's happening, maybe by examining the remote machine's Windows Event log. – wOxxOm Oct 06 '15 at 12:00
  • Dear wOxxOm I have found the solution for that --::ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c", "F:\\Softwares\\PsTool\\PsExec.exe \\\\xx.xx.xx.xx -u Administrator -p yyyy \"c:\\batch\\createFolder.bat\""); – Pankaj Dagar Oct 08 '15 at 05:51

1 Answers1

1

I have tried this and it's work: NOte-:F:\Softwares\PsTool is a path of PsExec.exe

 ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c",
                    "F:\\Softwares\\PsTool\\PsExec.exe \\\\xx.xx.xx.xx -u Administrator -p yyyy \"c:\\batch\\createFolder.bat\"");
Pankaj Dagar
  • 87
  • 10