2

I am unsure if context is the right word to use here but what i mean is something like

cd .\test
test.exe

test.exe is located in the folder test and I want to run it from the folder test, I know I can run

.\test\test.exe

but I need test.exe to be run from the folder test.

Is there a way to run both commands in the same "context"?

I have tried:

String cmd1 = "cmd /C cd test";
String cmd2 = "test.exe";
CommandLine cmdl1 = CommandLine.parse(cmd1);
CommandLine cmdl2 = CommandLine.parse(cmd2);
DefaultExecutor exec = new DefaultExecutor();
exec.execute(cmdl1);
exec.execute(cmdl2);

but as expected it could not find test.exe.

user3669539
  • 139
  • 1
  • 9
  • have you tried something like: `cd .\test && .\test.exe` – SnakeDoc Jul 06 '15 at 18:12
  • @SnakeDoc Thanks! that's exactly what I needed. I should've searched how to run 2 commands in the same line instead of just searching for stuff about commons exec. Can you move your comment to a post so I can mark the question as answered. – user3669539 Jul 06 '15 at 18:23

1 Answers1

0

I would try executing both commands joined together using the && operator.

Like:

cd .\test && .\test.exe

This will first change directories, and if successful, execute the test.exe executable in that directory. If the change directory is not successful, the second half of the command will not execute.

SnakeDoc
  • 13,611
  • 17
  • 65
  • 97