[英]Call a shell script in java?
是否可以在java類中調用shellcript或shellcode?
我的代碼(以靜態方法):
Runtime rtime = Runtime.getRuntime();
Process child = rtime.exec("/bin/bash");
BufferedWriter outCommand = new BufferedWriter(new
OutputStreamWriter(child.getOutputStream()));
outCommand.write("streamer -c /dev/video0 -b32 -o test.jpeg");
outCommand.flush();
outCommand.close();
child.destroy();
但是我得到這個錯誤,如果我在我的jsp頁面(tomcat6)中嘗試這個代碼:
java.security.AccessControlException:拒絕訪問(java.io.FilePermission / bin / bash execute)
解決這個問題的任何方法?
編輯 :ls -l / bin / bash向我展示了以下內容:
-rwxr-xr-x 1 root root 875596 2009-09-14 07:09 / bin / bash
謝謝
嘗試禁用安全管理器。 編輯/etc/init.d/tomcat6
並更改:
TOMCAT_SECURITY=yes
改為:
TOMCAT_SECURITY=no
然后重啟Tomcat:
/etc/init.d/tomcat6 restart
如果它有效,則由您來決定是否完全禁用安全管理器是否可接受(使用它實際上是不正常的IMO)。
如果可能,嘗試在單個exec調用中運行它。
Process p = Runtime.getRuntime().exec(args);
其中args是一個字符串數組的參數。
String[] args = new String[] {"/bin/bash", "streamer", "-c", "/dev/video0", "-b32", "-o", "test.jpeg" };
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.