我正在尝试通过java访问Ubuntu中的通知气泡
这是我的代码
class TestOSD{
public static void main(String[] args) throws Exception{
String[] cmmd = {"/usr/bin/notify-send -t 10000 \"Hello OSD\" \"This is my first programmatic OSD notification\""};
System.out.println("This is said : Hello OSD");
Runtime.getRuntime().exec(cmmd);
}
}
我在命令行中获取此堆栈跟踪
Exception in thread "main" java.io.IOException: Cannot run program "/usr/bin/notify-send -t 10000 "Hello OSD" "This is my first programmatic OSD notification"": java.io.IOException: error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
at java.lang.Runtime.exec(Runtime.java:593)
at java.lang.Runtime.exec(Runtime.java:466)
at TestOSD.main(TestOSD.java:6)
Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
at java.lang.ProcessImpl.start(ProcessImpl.java:65)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
... 3 more
基本上我无法理解 Runtime 类的 exec()
方法的重载?有人可以在这方面帮助我吗?
最佳答案
我认为问题在于它正在寻找整个字符串作为要启动的进程的名称。试试这个:
String[] cmd = { "/usr/bin/notify-send",
"-t",
"10000",
"Hello OSD This is my first programmatic OSD notification"};
这应该将进程的名称与参数分开,并将每个参数与其余参数分开。
关于java - 通过 Java 发出 OSD 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8987485/