我想从我的程序运行一个shell脚本,但它似乎没有做任何事情.我在linux终端直接运行相同的命令,它工作正常,所以我猜它是我的java代码.正如您所看到的,我首先使用PrintWriter将命令写入shell脚本,但我希望这不会影响shell脚本本身的运行.任何帮助,将不胜感激!
public static void main(String[] args) {
// TODO Auto-generated method stub
String nfdump = "nfdump -o csv -r /home/shane/Documents/nfdump/nfcapd.201211211526>blank.txt";
try {
FileWriter fw = new FileWriter("/home/shane/Documents/script.sh");
PrintWriter pw = new PrintWriter(fw);
pw.println("#!/bin/bash");
pw.println(nfdump);
pw.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Process proc = null;
try {
proc = Runtime.getRuntime().exec("sh /home/shane/Documents/script.sh");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud) 如果我使用的是基于AspectJ的Spring AOP,那么我是否可以配置我的方面以使用加载时间编织?或者,当使用基于AspectJ的方法时,Spring AOP是否也支持运行时/编译时编织?
我有一个包含以下代码的shell脚本;
#!/bin/bash
nfcapd -z -w -t30 -p 2055 -l /home/shane/Documents/nfdump
Run Code Online (Sandbox Code Playgroud)
我的问题是,当我执行shell脚本,上面的命令执行一遍又一遍(它捕获网络流量从路由器),但我想它在30秒后停止.在终端我只按Ctrl+ c,有一种方法在一定时间t后执行这个命令(Ctrl+ c)吗?