1

I want to get rid of a .bat file in java and have the code post directly to CMD.

I have tried multiple variances of the below but i'm not getting it right.

The .bat file contains the following:

CD C:\"Program Files (x86)"\"UiPath Platform"\UIRobot.exe -file C:\ProgramData\UiPath\Projects\DM9\Main.xaml

I would like Java to post this directly to CMD instead.

Currently my code looks like:

String test = in.readUTF();

         if (test.equals("Start"))
         {
             String[] command = {"cmd.exe", "/C", "Start", "C:Unipath\\start.bat"};
             Process child = Runtime.getRuntime().exec(command);
         }

Any advice?

Thanks in advance.

Gordon_Dev
  • 15
  • 2

2 Answers2

0

You haven't actually specified the problem, but I can run a batch file no problem without the cmd.exe argument. i.e. batch file

echo off
echo %1

can be run using

String[] command = {"test.bat", "HELLO"};
Process proc = Runtime.getRuntime().exec(command);

So I suspect your problem lies either with the cmd.exe argument or with the fact that your batch command doesn't seem to be valid

CD C:\"Program Files (x86)"\"UiPath Platform"\UIRobot.exe -file C:\ProgramData\UiPath\Projects\DM9\Main.xaml

Is this a Change Directory command with three arguments, a filename, a -file then another filename. Have you tested the batch file by itself?

Ross Drew
  • 8,163
  • 2
  • 41
  • 53
  • 1
    Hi Ross, i have resolved the issue. The .bat file worked perfectly, because java didn't post the cmd command to command prompt it executed a lot quicker. The designer also added no content to the cmd command so it seemed as though nothing was happening. I had him assign an output on that command and it worked perfect! thank you so much – Gordon_Dev Sep 14 '17 at 08:46
  • You're welcome, please upvote and accept if it helped @Gordon_Dev – Ross Drew Sep 14 '17 at 10:33
  • 1
    Hi Ross, i cant up vote due to reputation. I wont forget to when i get there. Few more points to go!! – Gordon_Dev Sep 18 '17 at 04:59
0

Refer to this link for detailed example: Run Dos commands using JAVA

Courtesy of @akshay-pethani's answer in below question. How do I execute Windows commands in Java?

spt025
  • 2,134
  • 2
  • 20
  • 26