我正在尝试使用 zenity 命令从用户那里获取输入。这是我传递给 zenity 的命令:
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;
}
虽然我得到了一个输出对话框,但标题只有第一个单词“Share”,问题的文本也只显示一个单词“Do”
这种奇怪的行为有什么解释吗?有什么工作?