gpt4 book ai didi

Java - apache commons exec,在同一个 "context"中运行2个命令

转载 作者:太空宇宙 更新时间:2023-11-04 13:41:11 24 4
gpt4 key购买 nike

我不确定上下文是否是在这里使用的正确词,但我的意思是类似

cd .\test
test.exe

test.exe 位于文件夹 test 中,我想从文件夹 test 运行它,我知道我可以运行

.\test\test.exe

但我需要从文件夹 test 运行 test.exe。

有没有办法在同一“上下文”中运行这两个命令?

我已经尝试过:

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);

但正如预期的那样,它找不到test.exe

最佳答案

我会尝试使用 && 运算符执行连接在一起的两个命令。

喜欢:

cd .\test && .\test.exe

这将首先更改目录,如果成功,则执行该目录中的 test.exe 可执行文件。如果更改目录不成功,则后半部分命令将不会执行。

关于Java - apache commons exec,在同一个 "context"中运行2个命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31252755/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com