runtime.exec

Runtime.getRuntime().exec()

你离开我真会死。 提交于 2019-11-27 05:09:38
I can not read a file only when database name contains like (new database (myid) etc. I give a following example code: dumpCommand = "C:/Program Files/MySQL/MySQL Server 5.0/bin/mysqldump -h"+hostName+user+databaseName; Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(dumpCommand); InputStream in = proc.getInputStream(); BufferedReader br=new BufferedReader(new InputStreamReader(in)); String line =null; while((line=br.readLine())!=null) { //able to read line only when database name like abc,datastore etc... System.out.println(line); } Suppose my database name de mo means when I print

How to set an environment variable in Java using exec? [duplicate]

你离开我真会死。 提交于 2019-11-27 04:38:21
问题 Possible Duplicate: How do I set environment variables from Java? I'm trying to set an environment variable, and read it back to verify it was actually set. I've got the following : import java.io.IOException; public class EnvironmentVariable { public static void main(String[] args) throws IOException { Runtime.getRuntime().exec("cmd.exe set FOO=false"); String s = System.getenv("FOO"); System.out.println(s); } } However, it appears that FOO is always null, meaning its probably not set

Using Quotes within getRuntime().exec

谁都会走 提交于 2019-11-27 04:37:08
I'd like to invoke bash using a string as input. Something like: sh -l -c "./foo" I'd like to do this from Java. Unfortunately, when I try to invoke the command using getRuntime().exec , I get the following error: foo": -c: line 0: unexpected EOF while looking for matching `"' foo": -c: line 1: syntax error: unexpected end of file It seems to be related to my string not being terminated with an EOF. Is there a way to insert a platform specific EOF into a Java string? Or should I be looking for another approach, like writing to a temp script before invoking "sh" ? Use this: Runtime.getRuntime()

java Runtime.getRunTime().exec & wildcards?

♀尐吖头ヾ 提交于 2019-11-27 04:33:23
i'm trying to remove junk files by using Process p = Runtime.getRuntime().exec(); it works fine as long as i do not use wildcards, i.e. this works: Process p = Runtime.getRuntime().exec("/bin/rm -f specificJunkFile.java"); while the following throws back "No such file or directory": Process p = Runtime.getRuntime().exec("/bin/rm -f *.java"); i should be able to do all the nice things as outlined here , right? Might I suggest that you let Java do this for you? Use file.listFiles() to get the list of files Use file.getName().contains(string) to filter them if needed iterate over the array

Java Runtime.getRuntime().exec() alternatives

╄→гoц情女王★ 提交于 2019-11-27 03:56:32
I have a collection of webapps that are running under tomcat. Tomcat is configured to have as much as 2 GB of memory using the -Xmx argument. Many of the webapps need to perform a task that ends up making use of the following code: Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec(command); process.waitFor(); ... The issue we are having is related to the way that this "child-process" is getting created on Linux (Redhat 4.4 and Centos 5.4). It's my understanding that an amount of memory equal to the amount tomcat is using needs to be free in the pool of physical (non-swap)

How to open the notepad file in java?

放肆的年华 提交于 2019-11-27 01:25:33
问题 I want to open Notepad in my Java program. Suppose that I have one button if I click this button the notepad will appear. I already have a file name and a directory. How can I implement this case? 回答1: Try if (Desktop.isDesktopSupported()) { Desktop.getDesktop().edit(file); } else { // dunno, up to you to handle this } Make sure the file exists. Thanks to Andreas_D who pointed this out. 回答2: (assuming you want notepad to open "myfile.txt" :) ProcessBuilder pb = new ProcessBuilder("Notepad.exe

Runtime.exec().waitFor() doesn't wait until process is done

大城市里の小女人 提交于 2019-11-27 01:03:44
问题 I have this code: File file = new File(path + "\\RunFromCode.bat"); file.createNewFile(); PrintWriter writer = new PrintWriter(file, "UTF-8"); for (int i = 0; i <= MAX; i++) { writer.println("@cd " + i); writer.println(NATIVE SYSTEM COMMANDS); // more things } writer.close(); Process p = Runtime.getRuntime().exec("cmd /c start " + path + "\\RunFromCode.bat"); p.waitFor(); file.delete(); What happens is that the file deleted before it actually executed. Is this because the .bat file contains

Reading streams from java Runtime.exec

两盒软妹~` 提交于 2019-11-26 23:04:12
I have the following snippet of code: Process proc = runtime.exec(command); errorGobbler = new ErrorStreamGobbler(proc.getErrorStream(), logErrors, mdcMap); outputGobbler = new OutputStreamGobbler(proc.getInputStream(), mdcMap); executor.execute(errorGobbler); executor.execute(outputGobbler); processExitCode = proc.waitFor(); where the gobblers are Runnable s which use a BufferedReader to read the input and error streams of the executing process. While this works most of the time, I get the occasional window (of about 2 minutes or so) where I get the processExitCode as 0, which indicates

Start CMD by using ProcessBuilder

陌路散爱 提交于 2019-11-26 22:18:18
问题 I am trying to start the CMD application in windows by using the following code, but it doesn't work as expected. Several examples from different websites shows that "cmd" as an argument in the ProcessBuilder construct should work. What do I have to do to make my Java app open the CMD application in windows? public class JavaTest { public static void main(String[] args) { ProcessBuilder pb = new ProcessBuilder("cmd"); try { pb.start(); System.out.println("cmd started"); } catch (IOException e

Why does exec() start a ADB daemon? [closed]

北城余情 提交于 2019-11-26 21:59:48
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I am building an app for some set of rooted phones I have. I was wondering if there is any way that I could uninstall a system app which comes with the phone running some code from my app. I have tried running commands like adb shell pm clear COM.PACKAGE.NAME from the phone itself by Runtime.getRuntime().exec()