我正在尝试通过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()方法的重载?在这方面,有人能帮我吗?
发布于 2012-01-24 21:21:32
我认为问题在于,它正在寻找整个字符串作为要启动的进程的名称。试着这样做:
String[] cmd = { "/usr/bin/notify-send",
"-t",
"10000",
"Hello OSD This is my first programmatic OSD notification"};这应该将进程的名称与参数分开,并将每个参数与其余参数分开。
https://stackoverflow.com/questions/8987485
复制相似问题