打开终端并在终端打开后运行命令

时间:2018-08-10 07:44:23

标签: java ubuntu terminal process runtime

所以我有一个sh脚本,位于我的下载文件夹中。使用此脚本,我设法在特定文件夹中打开终端:

String command = "/usr/bin/nome-terminal.wrapper"; 
File workDir = new File("/home/user/Downloads");
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(command, null, workDir)

并且比我想在终端加载后运行脚本,所以我用以下命令替换了上面的脚本:

String command= "/usr/bin/nome-terminal.wrapper -e 'myScript.sh; bash'";
File workDir = new File("/home/user/Downloads");
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(command, null, workDir)

但是我得到的错误是:here was an error creating the child process for this terminal. Failed to execute child process “'myScript” (No such file or directory)

注意:我不想直接运行脚本。我要终端运行它

更新

我尝试使用这个:

String[] cmdArray = new String[2];
cmdArray[0] = "usr/bin/gnome-terminal.wrapper";
cmdArray[1] = "myScript.sh";

Process process = Runtime.getRuntime().exec(cmdArray, null,new File("/home/user/Downloads"));

但是我收到错误消息:java.io.IOException: Cannot run program "usr/bin/gnome-terminal.wrapper" (in directory "/home/user/Downloads"): error=2, No such file or directory,因为他试图在我的Downloads文件夹中找到终端exe。

0 个答案:

没有答案
相关问题