工作,我試圖從使用zenity命令的用戶輸入。下面是我傳遞給zenity命令:Zenity bash命令不使用Java
zenity --question --title "Share File" --text "Do you want to share file?"
下面是一個使用Java來執行命令的代碼:
private String[] execute_command_shell(String command)
{
System.out.println("Command: "+command);
StringBuffer op = new StringBuffer();
String out[] = new String[2];
Process process;
try
{
process = Runtime.getRuntime().exec(command);
process.waitFor();
int exitStatus = process.exitValue();
out[0] = ""+exitStatus;
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = reader.readLine()) != null)
{
op.append(line + "\n");
}
out[1] = op.toString();
}
catch (Exception e)
{
e.printStackTrace();
}
return out;
}
雖然我得到的輸出對話框,標題只有第一單詞「共享」,問題的文本還顯示只有一個字「做」
是否有任何解釋這個奇怪的行爲呢?什麼是工作?
你必須在命令字符串變量正確的報價? –
@EtanReisner在上面提到的zenity命令是execute_command_shell方法的第一行的輸出 – gonephishing
你剝奪'命令:'關閉它呢?好。聽起來像某些東西不是通常將命令解析爲shell命令。 WillShackleford的回答涵蓋了(儘管笨拙地)使用一系列參數來代替。這可能是最好的答案。 –