Need help with Runtime.getRuntime().exec
If there is a better place to post please let me know. I need some help understanding what is going on and was hoping someone might be able to provide some information. I would like to use Runtime.getRuntime().exec to copy a file in linux. Here is the code I am using:
try {
Process p = Runtime.getRuntime().exec("cp -v foo foo2");
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
} catch (IOException e) {
e.printStackTrace();
If I use cp, with the System.out.println(line) I can see that it has copied and of course when I check the command line indeed it has. My problem is that I really need to use the dd command, but I can't see the output that dd displays. It copies the file just fine but I need the output. If someone can provide some explaination or help I would really appreciate it. Thanks.
By default, dd sends its output to stdout, so any status messages it has go to stderr. Use getErrorStream (double check the docs for the method name) just like you're currently using getInputSTream.
Similar Messages
-
I want to create a perfect remote shell with Runtime.getRuntime(). I just can't get it to change directories. I want that if the remote user type "cd.." he changes the directory. At the moment, I can't get anything else than the "user.dir" directory.
Is there anyway to send additionnal commands to cmd.exe after the Runtime.getRuntime().exec(). Because at the moment I'm running these commands:
cmd[0] = "cmd.exe" ;
cmd[1] = "/C" ;
cmd[2] = commandString;
After that I just wanna do stuff as if I really was at the computer and had a cmd.exe window open. I tried the output stream, I tried placing "&&" in front of the commandString(worked when I did it in cmd window), tried doing multiple Runtime.getRuntime().exec(). Starting to pull my hair out here.Because essentially I want this to be a remote shell.
So I need it to accepts commands such as cd to change
around the directory so the person can navigate the
computer.
I just managed to be able to do it in one command
line. For example I would send "cd c:\downloads dir"
to the server and it would work but I would really
like to keep track of the working directory so the
user wouldn't always have to change the directory.Then you don't Runtime.exec() once for each command the user types. You Runtime.exec() a shell once, and pass what the user types and the shell's responses via the in/out streams available from the Process class. -
Need help with Runtime.exec()
I need help getting my program to run a different java program through the command prompt using the runtime.exec() method. This is my code so far:
import javax.swing.JOptionPane;
import javax.swing.JDialog;
import javax.swing.JButton;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.BoxLayout;
import javax.swing.Box;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import javax.swing.JTabbedPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.*;
//import java.Original.*;
//import java.Turtle.*;
//import jav.Turtle.galapagos.*;
public class JavaMenu extends JPanel
JFrame frame;
JLabel label;
JButton select;
String labDescription = "Java labs created in class.";
String turtleDescription = "Turtle labs created in class";
String creationDescription = "Java programs created on my own.";
public JavaMenu(JFrame frame)
super(new BorderLayout());
JPanel lab = labDialog();
//JPanel turtle = turtleDialog();
//JPanel creation = creationDialog();
label = new JLabel("Click Select Program to run the program.", JLabel.CENTER);
this.frame = frame;
Border padding = BorderFactory.createEmptyBorder(20,20,5,20);
lab.setBorder(padding);
//turtle.setBorder(padding);
//creation.setBorder(padding);
JTabbedPane tab = new JTabbedPane();
tab.addTab("Java Labs", null, lab, labDescription);
//tab.addTab("Turtle Labs", null, turtle, turtleDescription);
//tab.addTab("Java Programs", null, creation, creationDescription);
add(tab, BorderLayout.CENTER);
add(label, BorderLayout.PAGE_END);
label.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
void setLabel(String newText)
label.setText(newText);
protected static ImageIcon createImageIcon(String path)
java.net.URL imgURL = JavaMenu.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
private JPanel labDialog()
final int numButtons = 25;
JRadioButton[] javalabs = new JRadioButton[numButtons];
final ButtonGroup group = new ButtonGroup();
select = null;
final String messageCommand2 = "Lab 02";
final String messageCommand3 = "Lab 03";
final String messageCommand4 = "Lab 04";
final String messageCommand41 = "Lab 04 Extra Credit 1";
final String messageCommand42 = "Lab 04 Extra Credit 2";
final String messageCommand5 = "Lab 05";
final String messageCommand51 = "Lab 05 Extra Credit";
final String messageCommand6 = "Lab 06";
final String messageCommand6b = "Lab 06";
final String messageCommand7 = "Lab 07";
final String messageCommand71 = "Lab 07 Extra Credit";
final String messageCommand8 = "Lab 08";
final String messageCommand8b = "Lab 08";
final String messageCommand81 = "Lab 08 Extra Credit";
final String messageCommand9 = "Lab 09";
final String messageCommand9b = "Lab 09";
final String messageCommand91 = "Lab 09 Extra Credit 1";
final String messageCommand92 = "Lab 09 Extra Credit 2";
final String messageCommand93 = "Lab 09 Extra Credit 3";
final String messageCommand9a = "Lab 09 American Flag";
final String messageCommand9t = "Lab 09 Texas Flag";
final String messageCommand0 = "Lab 10";
final String messageCommand0b = "Lab 10 Hi Lo Game";
final String messageCommand01 = "Lab 10 Extra Credit 1";
final String messageCommand02 = "Lab 10 Extra Credit 2";
javalabs[0] = new JRadioButton("Lab 02 100 Point Version");
javalabs[0].setActionCommand(messageCommand2);
javalabs[1] = new JRadioButton("Lab 03 100 Point Version");
javalabs[1].setActionCommand(messageCommand3);
javalabs[2] = new JRadioButton("Lab 04 100 Point Version");
javalabs[2].setActionCommand(messageCommand4);
javalabs[3] = new JRadioButton("Lab 04 Extra Credit 1");
javalabs[3].setActionCommand(messageCommand41);
javalabs[4] = new JRadioButton("Lab 04 Extra Credit 2");
javalabs[4].setActionCommand(messageCommand42);
javalabs[5] = new JRadioButton("Lab 05 100 Point Version");
javalabs[5].setActionCommand(messageCommand5);
javalabs[6] = new JRadioButton("Lab 05 Extra Credit");
javalabs[6].setActionCommand(messageCommand51);
javalabs[7] = new JRadioButton("Lab 06A 100 Point Version");
javalabs[7].setActionCommand(messageCommand6);
javalabs[8] = new JRadioButton("Lab 06B 100 Point Version");
javalabs[8].setActionCommand(messageCommand6b);
javalabs[9] = new JRadioButton("Lab 07 100 Point Version");
javalabs[9].setActionCommand(messageCommand7);
javalabs[10] = new JRadioButton("Lab 07 Extra Credit");
javalabs[10].setActionCommand(messageCommand71);
javalabs[11] = new JRadioButton("Lab 08A 100 Point Version");
javalabs[11].setActionCommand(messageCommand8);
javalabs[12] = new JRadioButton("Lab 08B 100 Point Version");
javalabs[12].setActionCommand(messageCommand8b);
javalabs[13] = new JRadioButton("Lab 08 Extra Credit");
javalabs[13].setActionCommand(messageCommand81);
javalabs[14] = new JRadioButton("Lab 09A 100 Point Version");
javalabs[14].setActionCommand(messageCommand9);
javalabs[15] = new JRadioButton("Lab 09B 100 Point Version");
javalabs[15].setActionCommand(messageCommand9b);
javalabs[16] = new JRadioButton("Lab 09 Texas Flag");
javalabs[16].setActionCommand(messageCommand9t);
javalabs[17] = new JRadioButton("Lab 09 American Flag");
javalabs[17].setActionCommand(messageCommand9a);
javalabs[18] = new JRadioButton("Lab 09 Extra Credit 1");
javalabs[18].setActionCommand(messageCommand91);
javalabs[19] = new JRadioButton("Lab 09 Extra Credit 2");
javalabs[19].setActionCommand(messageCommand92);
javalabs[20] = new JRadioButton("Lab 09 Extra Credit 3");
javalabs[20].setActionCommand(messageCommand93);
javalabs[21] = new JRadioButton("Lab 10 A 100 Point Version");
javalabs[21].setActionCommand(messageCommand0);
javalabs[22] = new JRadioButton("Lab 10 B 100 Point Version");
javalabs[22].setActionCommand(messageCommand0b);
javalabs[23] = new JRadioButton("Lab 10 Extra Credit 1");
javalabs[23].setActionCommand(messageCommand01);
javalabs[24] = new JRadioButton("Lab 10 Extra Credit 2");
javalabs[24].setActionCommand(messageCommand02);
for (int k = 0; k < numButtons; k++)
group.add(javalabs[k]);
javalabs[0].setSelected(true);
select = new JButton("Select Program");
select.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
String command = group.getSelection().getActionCommand();
if (command == messageCommand2)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
try
Runtime.getRuntime().exec(new String[] {"cmd", "set classpath=D:/Documents and Settings/Yinon Michaeli/My Documents/CS/java/Labs02", "path C:/j2sdk1.4.0/bin", "java Lab020"});
//File file = new File("java/Labs02");
//Runtime.getRuntime().exec(new String[] {"rundll32", "url.dll,FileProtocolHandler","file:///" + file.getAbsolutePath()});
catch (Exception a)
JOptionPane.showMessageDialog(frame, "Error: Exception.", "Error", JOptionPane.ERROR_MESSAGE);
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand3)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand4)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand41)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand42)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand5)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand51)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand6)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand6b)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand7)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand71)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand8)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand8b)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand81)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand9)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand91)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand9t)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand9a)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand9b)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand92)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand93)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand0)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand0b)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand01)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
if (command == messageCommand02)
int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (confirm == JOptionPane.YES_OPTION)
setLabel("Awesome!");
else if(confirm == JOptionPane.NO_OPTION)
setLabel("You've got to be kidding!");
return;
return create2ColPane(labDescription + ":", javalabs, select);
private JPanel createPane(String description, JRadioButton[] radioButtons, JButton showButton)
int numChoices = radioButtons.length;
JPanel box = new JPanel();
JLabel label = new JLabel(description);
box.setLayout(new BoxLayout(box, BoxLayout.PAGE_AXIS));
box.add(label);
for (int k = 0; k < numChoices; k++)
box.add(radioButtons[k]);
JPanel pane = new JPanel(new BorderLayout());
pane.add(box, BorderLayout.PAGE_START);
pane.add(showButton, BorderLayout.PAGE_END);
return pane;
private JPanel create2ColPane(String description, JRadioButton[] radioButtons, JButton showButton)
JLabel label = new JLabel(description);
int numPerColumn = radioButtons.length/2;
JPanel grid = new JPanel(new GridLayout(0, 2));
for (int k = 0; k < numPerColumn; k++)
grid.add(radioButtons[k]);
grid.add(radioButtons[k + numPerColumn]);
JPanel box = new JPanel();
box.setLayout(new BoxLayout(box, BoxLayout.PAGE_AXIS));
box.add(label);
grid.setAlignmentX(0.0f);
box.add(grid);
JPanel pane = new JPanel(new BorderLayout());
pane.add(box, BorderLayout.PAGE_START);
pane.add(showButton, BorderLayout.PAGE_END);
return pane;
private static void createAndShowGUI()
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("Java Programs");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JavaMenu newContentPane = new JavaMenu(frame);
newContentPane.setOpaque(true);
frame.setContentPane(newContentPane);
frame.pack();
frame.setVisible(true);
public static void main(String[] args)
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}Why are you posting hundreds of lines of code not related to the problem??? 99.9% of the code you posted has absolutely nothing to do with using the Runtime.exec() method.
Create a simple test program that simply tries to invoke the Runtime.exec() method. Once you get that working, then you incoporate it into you real program. Don't clutter the forum with unnecessary code.
public class WindowsFileProtocolHandler
public static void main(String[] args)
throws Exception
String[] cmd = new String[4];
cmd[0] = "cmd.exe";
cmd[1] = "/C";
cmd[2] = "java";
cmd[3] = "YourClassHere";
Process process = Runtime.getRuntime().exec( cmd );
} -
Problems with Runtime.getRuntime().exec in Windows 2000
Hello,
I have a batch file that I want to run from my java application. My code is the following:
try {
Runtime.getRuntime().exec("cmd.exe /c C:\\temp\\shortcut.bat");
} catch (Exception e) {
System.out.println(e.getMessage());
}I was developing on windows XP and it worked just fine. But then I tested it on windows 2000 and it didn't work. The batch file is okay, because if I run the batch file myself it works just fine, even from the command line. I get no errors what so ever, it just doesn't do anything...
Can somebody help me with this?
thx in advancethank you all so much
I figured it out... It was a combination of two things that went wrong.
First one: in my batch file I had:
cd C:\tempwhich worsk fine in XP, but in it doesn't in 2000. In 2000 it has to be:
C:
cd \temp But just changing that wasn't enough, I also needed the "start"
Now it works just fine on 2000, hopefully it'll still work on xp as well.
THX! -
Need help with Runtime class in UNIX
I am attempting to kick off a C++ executable from within java. This class is called through a UI.
The executable runs in the form of the exec followed by name=value pairs, ie [path/exec] [n=v] [n=v] ... and runs fine from the command line.
Examples: These don't kick it off, but don't error either.
String cmd[] = {"/bin/sh","-c","[path]/[exec] [n=v]};
String cmd[] = new String[3];
cmd[0] = "[path]/[exec]";
cmd[1] = "[n=v]";
cmd[2] = "[n=v]";
Process p = Runtime.getRuntime().exec(cmd);
I'm thinking it may be an environment issue, ie env vars not set because the only way I can get this to work is to put the command in a shell script that sets the env vars and kicks off the executable. Like:
String cmd[] = {"/bin/sh","-c","/[path]/test.sh"};
I'd prefer to kick this off from the java code. It sounds like I need to find a way to shell out, run our script to set env vars, then kick off the exec. This is my first attempt w/ using Runtime, so maybe I'm missing something.
Thanks in advance for the help.I think this sort of thing will depend upon the shell you're in. When you use Runtime.exec you (might) lose your "parent" shell's environment variables - this question shows up here now and again, here's one thread that might help:
http://forum.java.sun.com/thread.jspa?threadID=468648&messageID=2172572
You might find some enlightenment on Roedy's Java Glossary here: http://mindprod.com/jgloss/exec.html
Hope that helped
Lee -
Problem with Runtime.getRuntime().exec
Hi ,
i'm using jBuilderX and windows 2000 server . My problem is that i can't
find why
in my code it doesn't work this:
import java.lang.*;
String command = new String("c:\\testd\\testf.bat"); // testf.bat -
batch file
Runtime.getRuntime().exec(command); // it doesn't
have any effect
Thanks in advance,What's it supposed to do?
I can definitely help you on this 1, but I'd really like to see your streamoutputs. You can get these from the Process object that is created, but you'll need to add some threaded listeners to get the data.
Is this possible? -
Weird behaviour with Runtime.getRuntime.exec() attempting to start IE
I have developed a sample scheduler that it a web page the user fill in and then create a process schedule by the Timer class. The process starts IE in order to automate data entry normally done by a user. The Java code run well but IE when start from the p = Runtime.getRuntime().exec() class freeze. Is anyone can tell if IE require special setting to run in background?
Here the Java code but once again it work well but IE freeze and cause the forked process to hang.
// The schedule task
public void scheduleTask(Object o) throws ApplicationException {
ScheduleBean sb = (ScheduleBean)o;
try {
Timer timer = new Timer(true);
RunReslotting rr = new RunReslotting();
timer.schedule(rr, sb.getSchedulingDate());
catch(IllegalArgumentException iae) {
throw new ApplicationException(iae.getMessage());
catch(IllegalStateException ise) {
throw new ApplicationException(ise.getMessage());
public class RunReslotting extends TimerTask {
protected RunReslotting() {
public void run() {
String[] cmdLineParam = transportProfile(2);
cmdLineParam[0] = "location=" + wr.getLocation();
cmdLineParam[1] = "loc_class=" + wr.getNewStrategy();
forkProcess("runie.bat", cmdLineParam);
private String[] transportProfile(int startAt) {
envProf = System.getenv();
profCmd = new String[envProf.size() + startAt];
itr = envProf.entrySet().iterator();
int i = startAt;
while (itr.hasNext()) {
entry = (Map.Entry)itr.next();
profCmd[i] = (String)entry.getKey() + "=" + (String)entry.getValue();
i++;
return profCmd;
private void forkProcess(String processName, String[] osParam) throws ApplicationException {
// Lance un nouveau process
p = null;
int i=0;
try {
p = Runtime.getRuntime().exec(processName, osParam);
// Vide les buffers du process pour eviter de geler
mcError = new MessageCatcher(p.getErrorStream());
mcOutput = new MessageCatcher(p.getInputStream());
mcError.start();
mcOutput.start();
i = p.waitFor();
if ( (i != 0) || (mcError.getMessage() != null) || (mcOutput.getMessage() != null) ) {
System.err.println("*** Process failed RC:" + i + " *** ");
if (mcOutput.getMessage() != null) {
System.err.println("Output messages: " + mcOutput.getMessage());
if (mcError.getMessage() != null) {
System.err.println("Error messages: " + mcError.getMessage());
throw new ApplicationException("*** Process failed *** ");
catch(IOException ioe) {
throw new ApplicationException(ioe.getMessage());
catch(InterruptedException ie) {
throw new ApplicationException(ie.getMessage());
Any suggestion will be appreciate. I�m working on that scheduler for a while and i'm desperate
Thanks
FrancisThis starts IE for me, no problem
String[] cmd = {"C:\\Program Files\\Internet Explorer\\iexplore.exe"};
Runtime.getRuntime().exec(cmd); -
Need help with runtime exe command
Does anybody know how to get the command with double quotes to work with runtime exe?
String cmd = s+" "+fileName;
fin = new BufferedReader(new InputStreamReader(Runtime.getRuntime().exe(cmd).getInputStream()));
if my s is 'grep -i RTU', the fin would have correct value.
but if my s is 'grep -i "RTU"', the fin doesn't have anything (nothing return from exe(cmd) ).
I tried printing out the cmd, it looks fine ( grep -i "RTU" filename ).
Even when I copy the print of cmd and execute it on unix prompt, it return correct value too.
I also tried excaping double qoutes with backslash. Still doesn't work.
Thank you so much in advanceI tried with the exec(String[]) instead of
exec(String).
Still doesn't work.
I'm using Java 2 SDK, Standard Edition Version
1.3.1_02I am afraid I can't help. I can't duplicate your problem - I have no difficulty passing arguments with or without quotation marks using JDK 1.3. I just wrote a test to be sure, and it worked fine. -
Not a developer but need help with runtime error, please
Hi, I have downloaded a game called Fishdom, but it will not open. I get a " The application has requested the Runtime to terminate it in an unusual way" error message. The dialog box is labeled "Microsoft Visual C++ Runtime Library".
I checked my programs and I have C++ '05, '08, and 2010. I am using XP SP3. I don't get this error at any other time.
I have asked Playrix (game distributor) about it and they seem relatively clueless about how to fix it. So, is there anything I can do to fix this error, or bypass the error so that the game will load? I've tried deleting and reinstalling the libraries and
that did not help.
Anything you can suggest will be very helpful, because I do want the game and do not want to argue with them about refunding my money for it.Hi CatsinQ,
Thank you posting in MSDN forum.
According to your description, could you please tell us when you installed the
Microsoft Visual C++ Runtime Library if there have any install errors?
If you can install the Microsoft Visual C++ Runtime Library successfully, I think that the issue is more related to the game. Therefore, I suggest you can ask the issue to Playrix
(game distributor), maybe it will better help you.
In addition, since the
Visual Studio General
Forum which discuss Visual Studio the VS IDE issue, so I suggest you can try Brian’s suggestion.
Best Regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey. -
Need help with Runtime error! Can't find "MediaDatabase" file! Folders are visible!
Hi, I have been searching a lot for an answer to this issue. Elements keeps crashing after about five minuets and giving me "Microsoft Visual C++ Runtime Library" "Runtime Error!" "R6025 - pure virtual function call". I am running Premiere Elements 9.0 on windows 8.1 and I am trying to
rebuild the "mediadatabase.db3" file, but cannot find it. I made my hidden folders visible, and followed the pathway, but I only get this. I have searched and searched but I can't find anything about windows 8.1. Only 7 and vista. Thanks in advance!Look for a line that resembles the following in the
actionscript of the Flash fla files... It is likely to be in the
first frame's code, but may not be.
xmlData.load("teamTSI_en.xml");
the '
xmlData' part of that is not likely to be the same as what's
in your file, it's a variable so it could be anything, and the file
names will be whatever your xml files are.
If you can post that line of code from each of the fla files,
someone may be able to tell you where you need to place the xml
files. -
NEED HELP WITH RUNTIME ERROR!
I have recently formated my laptop and installed Adobe Reader. Every time I try to open a .pdf I get the message below:
Runtime Error!
Program: c:\program files\adobe\reader 9.0\readeacroRd32.exe
This application has requested the Runtime to terminate it in an unusual way. Please contact the applications support team for more information.
I always click to report it to windows but there is no link to fix this issue. What can I do?
Thanks.That hotfix applies to XPSP2. Is that what you've installed? If so,
you should probably upgrade to SP3, which includes a later version
of that and many other msvc files. If you're not using XP, then
that's not the solution.
Noel -
Kill "runtime.getruntime().exec"-generated processes with control-c?
Hi there,
In my java program I create 2 processes with "runtime.getruntime().exec", but when I stop my java program pressing control-c these 2 processes remains running and I have to kill them using linux command "kill".
How can I program my code in order to kill these 2 processes when stopping my java program with control-c?
I tried next but it didn't work for me:
try {
final Process proc = Runtime.getRuntime().exec ( "java ControlCProblemDemo" );
Runtime.getRuntime().addShutdownHook(
new Thread(){
public void run(){
proc.destroy();
while ( true );
} catch( IOException ioe ) {
System.err.println( ioe );
}Thank you very much in advance.
Josuéso are you saying proc.destroy() does nothing?
are you sure it's getting executed?
is there an error?
too little info here -
Unable to execute Runtime.getRuntime().exec(
Hello,
I am new to Java programming and trying to execute (OS is Linux) an external jar File with the command:
Runtime.getRuntime().exec("nohup java -jar SeismicAgents.jar &");It should start the SeismicAgents.jar and write the output to nohup.out.
This works perfectly if I just enter the command at the command line.
But upon starting it from within my program, the process seems to be started (I can see it when executin "ps aux"), but it is obviously not running as no input is written to nohup.out and the file which SeismicAgents.jar should generate is not generated.
I also tried the following code:
String cmd[] = {"nohup", "java", "-jar", "SeismicAgents.jar", "&"};
Runtime.getRuntime().exec(cmd);But I am experiencing the same problem here.
Executing something like
Runtime.getRuntime().exec(ls);works without problems...
Can anyone help?Runtime.getRuntime().exec("nohup java -jar
SeismicAgents.jar &");Java does not interprete the '&' character. Neither does
nohup. You would have to prefix this with /bin/sh -c, put
the rest in quotes and, most importantly, redirect input
and output somewhere. Without redirection, it is the task
of your java program to feed the subprocess with input
and drain its stdout and stderr buffers.
Executing something like
Runtime.getRuntime().exec(ls);works without problems...It is hard to believe this. Either it should be "ls" or
ls is string variable containing the relevant string,
but even then I would be surprised if you see any
output on the command line. At least I don't get
anything with public class bla {
public static void main(String[] argv) throws Exception {
Runtime.getRuntime().exec("ls");
}If you don't want a "/bin/sh -c" hack, you may want to
try http://www.ebi.ac.uk/~kirsch/monq-doc/monq/stuff/Exec.html .
Harald. -
Syntax of Runtime.getRuntime().exec()
i hava batch file command (genXML) in directory C:\update ,this command syntax is: genXML sourceFile resultFile outputDirectory
how can I run the command with Runtime.getRuntime().exec() ?
Thanksi hava batch file command (genXML) in directory
C:\update ,this command syntax is: genXML sourceFile
resultFile outputDirectory
how can I run the command with
Runtime.getRuntime().exec() ?
Thanksuse the
public Process exec(String[] cmdarray)
version of exec as follows:
where genProg is the path and name of your genXML program
ie. genProg = "C:\\update\\genXML.exe"
String[] cmd = {genProg, source, results, outputDir}; -
Need Help with getRuntime.exec()!!!
I'm stuck and i could use some assistance. When I use Runtime.getRuntime.exec("regedit.exe /e ... HKEY_LOCAL_MACHINE\\SOFTWARE")
where ... is some directory path like C:\Documents and Settings\
It doesnt work becuase the "Documents and Settings" either:
#1, is too long
#2, has spaces in it.
What would be the solution to this without having to do some crazy string manipulation? The location of the directory path I want the registry file to export to is stored in a String that is used in many places and changes all the time. ThanksThis is happening because Runtime.exec is breaking up your path into three separate arguments.
You can use the version of .exec that takes a String array for the command:
String myCommand = new String[3];
myCommand[0]="regedit.exe /e"
myCommand[1]="C:\Documents and Settings\...";
myCommand[2]="HKEY_LOCAL_MACHINE\\SOFTWARE";
Runtime.exec(myCommand,null, null);
Maybe you are looking for
-
I use this feature to view smaller fonts / e-mails frequently so will downgrade back to Firefox 3.x if it doesn't work in 4. This is the same feature that you would use on an iPhone for instance to enlarge the screen view. Also, I am a running the ve
-
Problem with Print Preview Urgent!
Hello BW Experts, 1.I am trying to use the Print functionality for web printing.In the print preveiew i see all the text in black and white.It is completely different from the page that is displayed in the browser. --I tried using the same print styl
-
Hi all, We have a Party and service without party options in Integration Directory.What is the differece between those two options. In which situation we can use those options. Thanks & Regards, sekhar
-
Greetings everyone! We are running an external OpenLDAP server which basically has the same type of instructions that an Active Directory config has. i.e. To get everything working I've had to follow Apple's posts about Active directory, the WIKI, cl
-
How much data is needed to download the whole creative suite?
How much data is needed to download the whole creative suite?