runtime.exec

how to get stdout and stderr in Runtime.exec in real-time?

半世苍凉 提交于 2019-12-13 05:42:27
问题 I have following code: Process runJob = null; try { runJob = Runtime.getRuntime().exec(args); InputStream cmdStdErr = null; InputStream cmdStdOut = null; cmdStdErr = runJob.getErrorStream(); cmdStdOut = runJob.getInputStream(); String line; BufferedReader stdOut = new BufferedReader (new InputStreamReader (cmdStdOut)); while ((line = stdOut.readLine ()) != null) { logger.info(line); } cmdStdOut.close(); // send error to Ab Initio and exit BufferedReader br = new BufferedReader(new

Executing a net use command

送分小仙女□ 提交于 2019-12-13 02:57:22
问题 I need to execute a net use command which is written in a batch file to enable a drive. Batch file is as follows: net use * /delete /Y net use l: \\<windows drive name> /user:<domain>\<username> <password> The above batch file enables a drive for me and its visible as L: drive to me. I need to execute this batch file through java code and then write the some files onto this drive. I am using the below code to execute this batch file: String[] array = { "cmd", "/C", "start", "C:/file.bat" };

Running .sh files with Java's exec in a different directory?

我的梦境 提交于 2019-12-13 02:29:10
问题 I'm writing a Java program MyAwesomeProgram that uses Process' exec function to run bash commands locally. My code is located in /home/a/b/c, and there are .sh files located in /home/a/b/d that I need to run. However, when I run my code: Process p; Runtime rt = new Runtime.getRuntime(); p = rt.exec("./home/a/b/d/shell.sh"); p.waitFor(); I receive an error: Exception in thread "main" java.io.IOException: Cannot run program "./home/a/b/d/shell.sh": java.io.IOException: error=2, No such file or

SED command not generating output file when called from app

老子叫甜甜 提交于 2019-12-12 19:49:15
问题 I am trying to write a java program that takes Strings in Java and replaces corresponding sequences of text in a perl script. Here is my code: String sedFirstLine = "'s/AAA/"+newFirstLine+"/'"; String sedNewCntr = "'s/BBB/"+newCntr+"/'"; String sedNewSpacing = "'s/SPACE/"+newSpacing+"/'"; String sedNewDmax = "'s/MAX/"+newDmax+"/'"; String sedInputFile = "/filepath/myPerlScript.pl" String sedOutputFile = "/filepath/myNewPerlScript.pl"; String[] cmdArray3 = {"sed", "-e", sedFirstLine,"-e",

Runtime.getRuntime().exec to pass parameter when prompted

喜欢而已 提交于 2019-12-12 12:04:08
问题 I am using the below java statement to start the PostgreSQL server from java code. I am using Runtime.getRuntime().exec() method to achieve this. final Process startServer = Runtime.getRuntime().exec("PostgreQL -D data/dir/ start"); Here when the server is SSL enabled and if the key is password protected, in command line it prompts for password (see below lines). In this case how can I pass the password. Is server running? starting server anyway waiting for server to start......Enter PEM pass

using android aapt in java program

不打扰是莪最后的温柔 提交于 2019-12-12 10:24:49
问题 I have been trying to execute the aapt command through a java program for quite some time now. My hunch is that I should be using the runtime.exec() command to make this happen. However, I have looked at other questions and answers and none seem to work for me. The command is: aapt package -u -f -F "/home/jay/testing_FILES.apk" "/home/jay/testing_FILES" where the /home/jay/testing_FILES is the original folder and the /home/jay/testing_FILES.apk is the packaged name and location of the final

Runtime.getRuntime().exec() execute two lines?

跟風遠走 提交于 2019-12-12 10:09:36
问题 I need to run two lines in Runtime.getRuntime().exec(), this two: cd %CMS_HOME% ant deploy Now is it possible to make a .bat file, but I think it is useless for two lines, is muss be easier! Someone any idea? 回答1: Put it in a .bat file. It's not useless; that's just how Runtime.exec works. You should look into using the ProcessBuilder class instead of Runtime.exec() . It was introduced in JDK 5 as the successor to Runtime.exec() . 回答2: Invoke the task programmatically from Java: File

Compiling C code from a Java program

独自空忆成欢 提交于 2019-12-12 05:58:43
问题 I am trying the following code to compile an external C program with a Java program import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public static void main(String[] args){ try{ Runtime rt=Runtime.getRuntime(); Process pr=rt.exec("cmd /c PATH=%PATH%;c:\\TC\\BIN"); pr=rt.exec("cmd /c c:\\TC\\BIN\\TCC.exe c:\\TC\\EXAMPLE.c"); pr=rt.exec("c:\\TC\\EXAMPLE.exe"); BufferedReader input=new BufferedReader(new InputStreamReader(pr.getInputStream())); String

java exec() run a db2 import command, waitfor() never return

天涯浪子 提交于 2019-12-12 05:01:35
问题 I used java process run a external command. This command is .bat file with some db2 commands. When I want use the process waiffor() return a result, I can't get anything. The program must be block. java code: ..... Runtime rt = Runtime.getRuntime(); Process p = null; String command = "db2cmd -c -w -i C:/import1.bat"; p = rt.exec(command); p.waitFor(); ..... import1.bat: @echo off db2 connect to text_DB user text using tesxt0114 db2 IMPORT FROM "C:\MVCMSInputFiles\IIS20121224180129.csv" OF DEL

Running hadoop jar command from JAVA using Runtime.exec

妖精的绣舞 提交于 2019-12-12 03:28:19
问题 I am trying to run an hadoop jar command from JAVA using Runtime.exec. Below is the sample code: Runtime.getRuntime().exec(new String[]{"bin/hadoop", "jar /home/hadoop/jar/test.jar /user/hduser/myinput/input /user/hduser/newoutput"}); However I am not getting the desired output. Below is my hadoop command which I want to execute from JAVA: bin/hadoop jar /home/hadoop/jar/test.jar /user/hduser/myinput/input /user/hduser/newoutput I am not getting any exception as well. Is the way Runtime