คำถามติดแท็ก runtime.exec

11
ฉันจะรันไฟล์แบตช์จาก Java Application ได้อย่างไร?
ในแอปพลิเคชัน Java ของฉันฉันต้องการเรียกใช้ไฟล์แบตช์ที่เรียก " scons -Q implicit-deps-changed build\file_load_type export\file_load_type" ดูเหมือนว่าฉันจะไม่สามารถเรียกใช้ไฟล์แบตช์ได้ด้วยซ้ำ ฉันหมดความคิด นี่คือสิ่งที่ฉันมีใน Java: Runtime. getRuntime(). exec("build.bat", null, new File(".")); ก่อนหน้านี้ฉันมีไฟล์ Python Sconscript ที่ฉันต้องการเรียกใช้ แต่เนื่องจากไม่ได้ผลฉันจึงตัดสินใจเรียกสคริปต์ผ่านไฟล์แบตช์ แต่วิธีนั้นยังไม่ประสบความสำเร็จ

4
จะทำให้ไปป์ทำงานกับ Runtime.exec () ได้อย่างไร?
พิจารณารหัสต่อไปนี้: String commandf = "ls /etc | grep release"; try { // Execute the command and wait for it to complete Process child = Runtime.getRuntime().exec(commandf); child.waitFor(); // Print the first 16 bytes of its output InputStream i = child.getInputStream(); byte[] b = new byte[16]; i.read(b, 0, b.length); System.out.println(new String(b)); } …
104 java  exec  runtime.exec 

4
ความแตกต่างระหว่าง ProcessBuilder และ Runtime.exec ()
ฉันกำลังพยายามเรียกใช้คำสั่งภายนอกจากรหัส java แต่มีความแตกต่างที่ฉันสังเกตเห็นระหว่างRuntime.getRuntime().exec(...)และnew ProcessBuilder(...).start(). เมื่อใช้Runtime: Process p = Runtime.getRuntime().exec(installation_path + uninstall_path + uninstall_command + uninstall_arguments); p.waitFor(); exitValue คือ 0 และคำสั่งถูกยกเลิกตกลง อย่างไรก็ตามด้วยProcessBuilder: Process p = (new ProcessBuilder(installation_path + uninstall_path + uninstall_command, uninstall_arguments)).start(); p.waitFor(); ค่าออกคือ 1001 และคำสั่งจะสิ้นสุดตรงกลางแม้ว่าจะwaitForส่งคืน สิ่งที่ฉันควรทำอย่างไรเพื่อแก้ไขปัญหาด้วยProcessBuilder?

โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.