runtime.exec

java processbuilder windows command wildcard

半世苍凉 提交于 2019-12-24 02:31:37
问题 I want to invoke a Windows command from Java. Using the following line works fine: ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/C", "find \"searchstr\" C://Workspace//inputFile.txt"); But I want to find the string in all text files under that location, tried it this way, ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/C", "find \"searchstr\" C://Workspace//*.txt"); But it does not work and there is no output in the Java console. What's the solution? 回答1: It looks like find is

mysqldump returns code 6 when run from java, but the same command works fine from command line

自古美人都是妖i 提交于 2019-12-23 20:14:48
问题 When I run the same command from Java via Runtime.getRuntime I get the return code 6. The same command works fine from command line: process = Runtime.getRuntime().exec(mysqldumpCommand); int processComplete = process.waitFor(); For those 2 commands I get the return code 6 when run from java and no dump. The work fine from command line(I don't have a password on the local env.) mysqldump --user=root --password= --host=localhost dbname > c:\temp\dumpfile.sql mysqldump --user=root --password=""

Restore PostgreSQL database using java

橙三吉。 提交于 2019-12-23 03:22:29
问题 im using the following code to Restore PostgreSQL database using java Runtime r = Runtime.getRuntime(); Process p; String cmd ="D:/Program Files/PostgreSQL/9.1/bin/pg_restore.exe --host localhost --port 5432 --username postgres --dbname mytestqq --role postgres --no-password --verbose D:\sathish\rawDatabase.backup"; p = r.exec(cmd); i have 42 tables in the rawDatabase.backup file but only one table is getting restored why the rest of the tables are not happening whats wrong in my code? thanks

Restore PostgreSQL database using java

匆匆过客 提交于 2019-12-23 03:22:27
问题 im using the following code to Restore PostgreSQL database using java Runtime r = Runtime.getRuntime(); Process p; String cmd ="D:/Program Files/PostgreSQL/9.1/bin/pg_restore.exe --host localhost --port 5432 --username postgres --dbname mytestqq --role postgres --no-password --verbose D:\sathish\rawDatabase.backup"; p = r.exec(cmd); i have 42 tables in the rawDatabase.backup file but only one table is getting restored why the rest of the tables are not happening whats wrong in my code? thanks

How to execute cmd commands via Java swing

做~自己de王妃 提交于 2019-12-22 18:38:16
问题 I have a file to print and I want to send him a custom water mark via java swing. i have 2 files NewJFrame.java and Test.java package test; import java.io.IOException; import java.io.OutputStream; /** * * @author shaharnakash */ public class NewJFrame extends javax.swing.JFrame { /** * Creates new form NewJFrame */ public NewJFrame() { initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this

Runtime.getRuntime().exec(), executing Java class

不羁岁月 提交于 2019-12-22 08:34:31
问题 I am executing Java class from inside my application. proc = Runtime.getRuntime().exec("java Test"); How can I recognize whether Test executed successfully or not (i.e. no exceptions)? Redirecting output / error: proc = Runtime.getRuntime().exec(new String[] { "java", mclass, ">NUL 2>test.txt" }); From cmd : java Main >NUL 2>test.txt 回答1: process.waitFor(); int exitCode = process.exitValue(); if(exitCode == 0) { // success } else { // failed } This works, if the Test is designed properly and

Get Java Runtime Process running in background

偶尔善良 提交于 2019-12-21 21:47:49
问题 I'm writing a java application where I require to run a process in background throughout the lifetime of the running application. Here's what I have: Runtime.getRuntime().exec("..(this works ok).."); Process p = Runtime.getRuntime().exec("..(this works ok).."); InputStream is = p.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); So, basically I print out every br.readLine() . The thing that I'm not sure about is how to implement

Android- Error during executing Runtime.getRuntime().exec() - Environment Null -ffmpeg

 ̄綄美尐妖づ 提交于 2019-12-21 21:38:25
问题 I have compiled ffmpeg library on ubuntu 11.10 and ported compiled files on android. After compiling i got libffmpeg.so successfully. It gets loaded on android successfully. I am doing it on ubuntu 11.10 eclipse android emulator. I have created a small test application which act as command prompt which accepts command from user and displays result. (testing ffmpeg commands) When i run simple commands like "ls", "ls -l" it works perfectly. but when i simply type " cd mnt " or " ffmpeg " as

The right way to kill a process in Java

心已入冬 提交于 2019-12-21 03:31:12
问题 What's the best way to kill a process in Java ? Get the PID and then killing it with Runtime.exec() ? Use destroyForcibly() ? What's the difference between these two methods, and is there any others solutions ? 回答1: If the process you want to kill has been started by your application Then you probably have a reference to it ( ProcessBuilder.start() or Runtime.exec() both return a reference). In this case, you can simply call p.destroy() . I think this is the cleanest way (but be careful: sub

Runtime.exec().waitFor() not actually waiting for

筅森魡賤 提交于 2019-12-20 12:15:20
问题 I've got some code that uses Runtime.exec() to run an external .jar (built as an IzPack installer). If I run this external.jar from the command line like so: java -jar external.jar Then the command prompt does not return control until the application is finished. However, if I run external.jar from within some java class, using: Process p = Runtime.getRuntime().exec("java -jar external.jar"); int exitCode = p.waitFor(); System.out.println("Process p returned: " + exitCode); Then p returns