1
我想在調試模式下使用Java與PS4環境變量集運行我的bash腳本。在調試模式下使用Java與PS4設置運行bash腳本
ProcessBuilder pb = new ProcessBuilder("/bin/bash" ,"-x", "/junk/leaptest.sh");
Map<String, String> env = pb.environment();
env.put("PS4", "${BASH_SOURCE}:::${LINENO}:::COV:");
final Process process = pb.start();
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
PrintWriter pw = new PrintWriter(process.getOutputStream());
String line;
while ((line = br.readLine()) != null) {
System.out.println("line no--->>" + line);
pw.println("2000");
pw.flush();
}
什麼我得到它的輸出不是在調試模式下運行,我的PS4 ENV未設置
同樣的事情工作時,我使用運行命令,
String[] cmd = new String[3];
cmd[0] = "/bin/bash"; // should exist on all POSIX systems
cmd[1] = "-xv";
cmd[2] = args[0];
String[] env = new String[1];
env [0] = "PS4=${BASH_SOURCE}:::${LINENO}::: COV:";
Runtime rt = Runtime.getRuntime();
System.out.println("Execing " + cmd[0] + cmd[1]);
Process proc = rt.exec(cmd,env);
什麼是'-x'選項?我在這裏找不到它:http://www.gnu.org/software/bash/manual/html_node/Invoking-Bash.html –
[root @〜]#cat /junk/leaptest.sh #!/ bin/bash echo「鍵入要檢查的年份(4位數字),然後按[ENTER]:」 讀取年份 if(((「$ year」%400)==「0」))|| (((「$ year」%4 ==「0」)&&(「$ year」%100!= 「0」)));那麼 回聲「$年是一個閏年。」其他 回聲「這不是閏年。」 網絡 [根@〜]#leaptest.sh 類型要檢查(4位)的年,然後按[ENTER]: [根@〜]#bash的-x /junk/leaptest.sh echo'鍵入要檢查的年份(4位數字),然後按[ENTER]:' 鍵入要檢查的年份(4位數),然後按[ENTER]: 讀取年份 – anish
設置PS4變量會導致設置-x輸出包括行號: – anish