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.

3
  • What has this to do with Javascript? Commented Sep 13, 2017 at 8:39
  • Sorry, removed tag Commented Sep 13, 2017 at 8:49
  • What is the problem? What doesn't work? What is the output? Commented Sep 13, 2017 at 9:16

2 Answers 2

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?

Sign up to request clarification or add additional context in comments.

3 Comments

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
You're welcome, please upvote and accept if it helped @Gordon_Dev
Hi Ross, i cant up vote due to reputation. I wont forget to when i get there. Few more points to go!!
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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.