Runtime execute command with arguments

hi
i need to execute the following command with arguments in java. this is how i would do it in cmd
C:\Users\name\File\root.exe -a192.168.1.0 -wpassword -p11 -cON   where 192.168.1.0 is the ipaddress and i have it in my java program as a string.similarly password is a string and 11 is the port number as an int in java..i need to execute this in java..
i just have this:
String[] command = {"C:\Users\name\File\root.exe", ......};thanks

d_khakh wrote:
also when i said this
String[] command = {"C:\Users\name\File\root.exe", ......};i meant i do not have anything in place of dots. its uncompleted..do not assume i got this part!Yeah, you should read the documents I pointed you to and try to fill in those dots. It really looks like you want someone to do it for you, and that ain't gonna happen (well it usually doesn't anyway).

Similar Messages

  • Executing query with arguments- issue when  parameter value contains '&'

    My application inserts 'First name', last name' and last upd date to the table. it inserts all the data properly. Next level I access the information along with other tables using same arguments. But it is not fetching any data. I noticed it happens whenever the '&' is included in the parameter (first name). eg:
    'Margaret & John'. From the logs I noticed that first name it is not taking what I passed. It just stripping the first name from '&' onwards and taking only 'Margaret'. Here is the example from the log. You could notice only 'Margaret' instead of 'Margaret & John' in place of first argument.
    <2007-03-29 11:35:51,425> <DEBUG> <default.collaxa.cube.ws> <Database Adapter::Outbound> <oracle.tip.adapter.db.DBInteraction executeOutboundRead> Executing query with arguments [Margaret , Cohen, 2007-03-29T11:35:51-06:00]
    Appreciate your help if you could give me a hint how to resolve this issue
    Thanks
    Reddy

    Hi Reddy,
    from the log it looks like the DbAdapter received the value as 'Margaret '. Because parameter binding is used by default, the database shouldn't try to interpret the & as it is inside a bind variable.
    Could it be that the & is getting dropped somewhere else? Marc was suggesting you put that value inside a CDATA section or escape it. He probably showed that but when he hit Post Message it displayed the escaped & as &. I think we should find out where that & got dropped though. Normally BPEL will preserve it.
    Thanks
    Steve

  • Runtime.exec command with spaces

    I'm having problems using exec on (unix) commands that take filenames as a parameter - eg chmod.
    The problem is that I've been blessed with some filenames which contain spaces and I can't figure out a way to pass these through.
    The code I'm trying is :
    String fs="/";
    String droot="home";
    String fname="tom test";
    String fullFileName=fs + droot + fs + fname;
    String outlist[] = runCommand("chmod 777 " + fullFileName );
    if fname contains no spaces, then this will work fine, but (as in the example above) if it contains a space, then I get an error (can't find files).
    Any ideas?
    Thanks
    Tom

    The reason that putting quotes around the filename works on the command line is that they affect how the command line interprets them.
    However, Runtime.exec does not intepret the quotes as special characters. If you have a space in an argument, you should use the Runtime.exec method that takes a String[] argument, and place each argument in an array element.

  • System (Runtime) execute command for copying the file

    Can any one tell me what is wrong with this - it throws an IOException
    String sourcepath = "C:"+File.separator+"pbx"+File.separator+"mantra"+File.separator+"vvvvv.mp3";
    String destinationpath = "C:"+File.separator+"rrr"+File.separator+"mantra"+File.separator+"mantra.mp3";
    Runtime rt=Runtime.getRuntime();
    try{
    String command="C:"+File.separator+"windows"+File.separator+"command /c copy "+sourcepath+" "+destinationpath;
    System.out.println(command);
    rt.exec(command);
    }catch(IOException ex){System.out.println("exception "+ex); ex.printStackTrace();}
    output:-
    C:\windows\command /c copy C:\pbx\mantra\vvvvv.mp3 C:\rrr\mantra\mantra.mp3
    exception java.io.IOException: CreateProcess: C:\windows\command /c copy C:\pbx\mantra\vvvvv.mp3 C:\
    rrr\mantra\mantra.mp3 error=2
    java.io.IOException: CreateProcess: C:\windows\command /c copy C:\pbx\mantra\vvvvv.mp3 C:\rrr\mantra
    \mantra.mp3 error=2
    at java.lang.Win32Process.create(Native Method)
    at java.lang.Win32Process.<init>(Win32Process.java:66)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Runtime.java:566)
    at java.lang.Runtime.exec(Runtime.java:428)
    at java.lang.Runtime.exec(Runtime.java:364)
    at java.lang.Runtime.exec(Runtime.java:326)
    at Test.main(Test.java:82)

    this is clear one...
    String sourcepath = "C:"+File.separator+"pbx"+File.separator+"mantra"+File.separator+"vvvvv.mp3";
    String destinationpath = "C:"+File.separator+"rrr"+File.separator+"mantra"+File.separator+"mantra.mp3";
    Runtime rt=Runtime.getRuntime();
    try{
    String command="C:"+File.separator+"windows"+File.separator+"cmd /c copy "+sourcepath+" "+destinationpath;
    // String command="copy "+sourcepath+" "+destinationpath;
    System.out.println(command);
    rt.exec(command);
    }catch(IOException ex){System.out.println("exception "+ex);
                ex.printStackTrace();}

  • Execute command with defined parameters

    Hi,
    I have a firefox addon, "Image Assistent", which enables you to open images with an image viewer. The only possibility is gThumb, which I do not like. So one makes a symbolic link. I have made one so it uses Feh. But I want Feh to be executed as "feh -ZF --hide-pointer". How do I do this?
    I made a tiny script feh.sh with "feh -ZF --hide-pointer" as content, but this lacks what image it should open. An alias doesnt work. So how can I get feh to open with said parameters?
    Thanks

    Use this as script
    #!/bin/sh
    feh -ZF --hide-pointer "$*"

  • Executing Commands with CachedRowSet

    Hi,
    Could anyone tell me if it is possible to execute a SQL querry against a cached row set? For example, the cached rowset has been populated with data about Customers with fields Name, Order, PartNo. I wish to retrieve the Name and Order fields for a specific PartNo. Any idea how I would do this?
    Thanks

    What I am doing right now is loading all the data at
    the same time. So I don't need to connect to the DB
    to fetch the information again.I see.
    >
    The reason why it is inefficient is that the search
    has to be performed about 100 or so times all
    sequentially.Why sequentially?
    Use an additional hash. The first time you go through the row set you populate the hash with the key being the part number and whatever other info you want associated with it being the data/value - probably as an array or even another hash.
    Then when you want info on a part num you use the hash rather than the row set.
    Note that excluding other information 100 times is very small in most terms.

  • Executing commands with game controller

    How can I map commands (such, uname -a for example) to the buttons on my controller?
    So far, I've gotten xf86-input-joystick to work with the following in my xorg.conf
    Section "InputDevice"
    Identifier "Dualshock2"
    Driver "joystick"
    Option "Device" "/dev/input/js0"
    EndSection
    and the following in the ServerLayout section
    InputDevice "Dualshock2" "SendCoreEvents"
    But for some retarded reason, xorg just seems to consider my controller to be another mouse: I can move the pointer with the arrows, buttons 1, 2, and 3 act as mouse buttons, etc.
    I know I set xorg.conf to map keyboard keys to separate buttons, but how do I map commands? For example, I want to map "mpc toggle" to the start button (button 9).

    ok, I solved this myself
    I just had to remap each button on the controller as another mouse button; for instance
    Section "InputDevice"
    Identifier "Dualshock2"
    Driver "joystick"
    Option "Device" "/dev/input/js0"
    Option "MapButton1" "button=9"
    Option "MapButton2" "button=10"
    Option "MapButton3" "button=11"
    Option "MapButton4" "button=12"
    Option "MapButton5" "button=13"
    Option "MapButton6" "button=14"
    Option "MapButton7" "button=15"
    Option "MapButton8" "button=16"
    Option "MapButton9" "button=17"
    Option "MapButton10" "button=18"
    Option "MapButton11" "button=19"
    Option "MapButton12" "button=20"
    Option "MapButton13" "button=21"
    Option "MapButton14" "button=22"
    Option "MapButton15" "button=23"
    Option "MapButton16" "button=24"
    EndSection
    so, that's that
    from there I've been able to map each button to a command using xbindkeys
    axis 1 (left stick) controlls the pointing, and the right stick seems to do scrolling
    awesome

  • Runtime (execute programs with java)

    Hello,
    I need your help. I need to run Internet Explorer when a menu item is clicked in a JMF Applet. Is this the code?
    //this is the class I created to run Internet Explorer
    class CorreIE {
    public static void main(String args[]) {
    try {
    Runtime cie = Runtime.getRuntime();
    Process prcs = cie.exec("C:\\Program Files\\Internet Explorer\\iexplore.exe");
    } catch(IOException ioe) { System.out.println(ioe); }
    //this is the action listener I created for the event
    if (ae.getSource()==ajuda) //abre o internet explorer com o ficheiro de ajuda
              CorreIE cie = new CorreIE();
              cie.show();
    IT DOESN'T WORK.... Please help!
    Thanks,
    XonaDick

    You have your code in a main method which will work if you run it stand alone
    Instatiate your class eg: RunTimeExec rte = new RunTimeExec();
    then access its run method eg : rte.runIExplorer();
    Try this
    import java.io.IOException;
    class RunTimeExec {
    public RunTimeExec(){
    public runIExplorer(){
    Runtime cie = Runtime.getRuntime();
    try {
         Process prcs = cie.exec("C:\\Program Files\\Internet Explorer\\iexplore.exe");
    } catch (IOException e) {
    // TODO Auto-generated catch block
         e.printStackTrace();
    it does work

  • Execute cmd command with spaces

    Hi dears,
    I am trying to execute a cmd command (shell comnmand), but I got no response from the console i,e it is not executed even no errors returned.
    here is my code to be executed
    import java.io.*;
    import java.util.*;
    public class TestCommand
         public static void main(String[] args)throws IOException
              String[] cmd={"Nvdkit notify.tcl ALL hameed1 hameed2"};//command with arguments
              String[] envo={"path=;","path=C:\\Program Files\\Novadigm"};//path of the file
              //String[] cmd2={"cmd.exe","\\C","dir"};
              Runtime rt = Runtime.getRuntime();
              Process pp = rt.exec(cmd);
              //pp.waitFor();
              writeProcessOutput(pp);
         static void writeProcessOutput(Process p)throws IOException
              InputStreamReader tempReader = new InputStreamReader(new BufferedInputStream(p.getInputStream()));
              BufferedReader br = new BufferedReader(tempReader);
              while(true)
                   String line = br.readLine();
                   if(line==null)
                        break;
                   System.out.println(line);
    }     Could you please assist?
    thanx in advance
    Edited by: hameedo on Sep 21, 2008 11:51 AM

    import java.io.*;
    import java.util.*;
    public class TestCommand
         public static void main(String[] args)throws IOException
              String[] cmd={"java","-version"};
              String[] envo={"path=;","path=C:\\Program Files\\Java\\jdk1.6.0_02\\bin"};
              String[] cmd2={"cmd.exe","\\C","dir"};
              Runtime rt = Runtime.getRuntime();
              Process pp = rt.exec(cmd,envo);
              //pp.waitFor();
              writeProcessOutput(pp);
         static void writeProcessOutput(Process p)throws IOException
              InputStreamReader tempReader = new InputStreamReader(new BufferedInputStream(p.getInputStream()));
              BufferedReader br = new BufferedReader(tempReader);
              while(true)
                   String line = br.readLine();
                   if(line==null)
                        break;
                   System.out.println(line);
    }     The above code won't executed correctely.
    I am trying to get java version, but no errors no iformation were returned!
    Coudl you please assist in this issue?
    thanx all

  • Runtime exec command parameters with SSH

    hey,
    Im trying to run a unix command using Process proc = Runtime.getRuntime().exec(command);
    It works fine until I tried to combine it with multiple commands.
    For example, I'm trying to run:
    ssh [email protected] 'ls -al'
    This returns a exit value of -1, command not found.
    ssh [email protected] ls works fine so I suspect its related to the extra parameters.
    I checked the Javadoc page for exec:
    The command argument is parsed into tokens and then executed as a command in a separate process. The token parsing is done by a StringTokenizer created by the call:
    new StringTokenizer(command)
    As expected, it tokenized:
    ssh
    [email protected]
    'ls
    -al'
    Is there any way to bypass this default tokenization by exec to include quotes as one token?
    If anyone has any ideas, let me know! Thanks!

    thanks, solves that part.. but if i use execute command with ssh and bsub(a clustering job queue-submitter), it does ot return the correct value.
    For example, if i do ssh [email protected] bsub -I ls using exec and the waitFor() method, the waitFor waits indefinitely.
    I can tell it ran the job and ended, because i checked via bjobs and it finished. So why isn't the java app getting the exit code from waitFor() back?
    If I run the program on the targeted machine, bsub -I ls, it works correctly.
    If i type in the console, ssh [email protected] bsub -I ls, it returns back the results correctly.
    info regarding bsub and bjobs here http://www.ncsa.uiuc.edu/UserInfo/Resources/Hardware/XeonCluster/Doc/Jobs.html

  • Using continuation character in EXECUTE command

    In SQL*Plus, the following sample EXECUTE command works fine
    EXECUTE MyProcedure(arg1, arg2)
    But if I try to break it into two lines:
    EXECUTE MyProcedure(arg1, -
    arg2)
    I get a character to number conversion error ORA-06502
    Both of the arguments are of VARCHAR2 type.
    I thought the hyphen character was supposed to let you continue a command on more than one line. How can I break up this command?

    The EXECUTE works with SQL*Plus and does not work from within SqlDeveloper
    The contents of the procedure, which is part of a package, seems to be irrelevant since the problem occurs even with an empty procedure body (just a NULL; statement).
    My platform is Windows2000. Database version is 11g. SQLDeveloper version is 1.2.1
    To reiterate, when I type on command line in SqlPlus there is no problem, when I run it from a script file from within SqlPlus there is not problem. The problem occurs only from within SqlDeveloper. Replacing the EXECUTE command with an anonymous block does work in either environment.
    It is difficult for me to show exactly what is in the called procedure since the machine it is running on is not connected to the internet and would require retyping the whole procedure out here -- that's why I tried the experiment with the NULL body with the exact same results as with the non NULL body.
    Message was edited by:
    user556531

  • Executing another program with command line arguments

    I am very new to Java, so bare with me.
    I have written an encryption/decryption program in C (that accepts command line arguments of the key, mode (encrypt/decrypt), and file), and I have written a GUI for it in Java. It accepts the filename (and has a button which opens the "File/Open" dialog), key, and mode, and has a button to Start the process of the encryption. I'd like for that "Start" button to call my encryption program in C (eep.exe) with the command line arguments of the file, key, and mode. This is what I have written so far :
    Start = new JButton("Start");
    Start.setBounds(150, 180, 90, 25);
    Start.addActionListener(new ActionListener() {     
    public void actionPerformed(ActionEvent ae) {
    Desktop.open(new File("C:\\eep.exe" + " " + filename + " " + mode + " " + key));
    However, I get the error "Cannot make a static reference to the non-static method open(File) from the type Desktop" on the Desktop.open command.
    What should I do? Is Desktop.Open the right way to go about this? If not, what is the right way to go about it?
    Thanks in advance.

    That has helped greatly, but I cannot pass command line arguments to it.
    Using :
    try {
        Desktop.getDesktop().open(new File("C:\\eep.exe"));
    catch (Exception e) {
       System.out.println("Error executing.");
    }I can execute eep.exe, but when I try to pass command line arguments to it, such as
    Desktop.getDesktop().open(new File("C:\\eep.exe" + " " + filename));it fails, get caught and prints "Error Executing."
    I have also tried loading the program, as well as some command line arguments into an array of strings :
    String[] cmdArray = {"C:\\eep.exe", filename};
    Desktop.getDesktop().open(new File(cmdArray));But it gives me the error "The constructor File(String[]) is undefined" on the
    new File (cmdArray)part of the command.

  • Execute an Unix command with pipe

    Hi,
    How do I execute a unix command with pipe from JAVA runTime.exec(cmd)? for example: "ls -l |wc -l"
    should return number of files. However, there is no output result. If I use "ls -l" as command argument, it gives file list.
    Here is my program:
    public static void main(String[] args) {
    try {
    Runtime runCmd = Runtime.getRuntime();
    System.out.println("sys testing");
    Process retProc = runCmd.exec(args[0]);
    BufferedReader bread = new BufferedReader
    (new InputStreamReader(retProc.getInputStream()) );
    String out = bread.readLine();
    while ( out != null ) {
    System.out.println(out);
    out = bread.readLine();
    DataOutputStream outSt = new DataOutputStream(retProc.getOutputStream() );
    outSt.writeChars(args[1]);
    outSt.flush();
    } catch (Exception ie) {
    ie.printStackTrace();
    Thanks in advance,
    Jeff

    I got my answer !
    No need to reply

  • 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 advance

    I 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.

  • EXECUTE DOS COMMANDS WITH JAVA

    I'm new to java and I want to execute dos commands by java
    can someone help me by by anyway?
    like tell me the packages or methods I need
    or give me links to sites?
    thanks

    No Arguments:
    try {
            // Execute a command without arguments
            String command = "ls";
            Process child = Runtime.getRuntime().exec(command);
            // Execute a command with an argument
            command = "ls /tmp";
            child = Runtime.getRuntime().exec(command);
        } catch (IOException e) {
        }With Arguments:
    try {
            // Execute a command with an argument that contains a space
            String[] commands = new String[]{"grep", "hello world", "/tmp/f.txt"};
            commands = new String[]{"grep", "hello world", "c:\\Documents and Settings\\f.txt"};
            Process child = Runtime.getRuntime().exec(commands);
        } catch (IOException e) {
        }

Maybe you are looking for

  • Mailbox can't access servers in Lion

    I have 3 mailboxes in "Mail."  It suddently started showing spinning circles by all of them, and I am getting "reports" from each of them that they can't connect with the server (timed out.)  I can got to the websites and see the mail Ok, however.  H

  • Oracle Database 11g: SQL Fundamentals I 1Z0-051 Question

    i bought the OCA Oracle Database 11g: SQL Fundamentals I Exam Guide (Exam 1Z0-051) and i am not sure do i have to read the whole book ! or just go through the exam objectives table ? because the book covers lots of topics that's not in the exam and i

  • I have Ver.31 on 2 computers but I only have a Super Smart tab page on 1. How do I get it back on my other laptop?

    I had a Super Smart tab on both of my laptops. When I updated to Version 31 one of my laptops lost the Super Smart tab feature. It has a "tab" feature where I can pin links but it just doesn't look as nice as the Super Smart tab does.

  • 64-bit or 32-bit Intel?

    I am assuming these new Intel machines are still the old 32-bit style. Is this correct? What are we sacrificing for back stepping? I work in a PC environment office with my G5 and it's amazing how much clearer and brigher my monitor (we all have the

  • Duplicate pages...a faster way

    In Adobe Professional: I need to duplicate pages 20 times. For example, a page with exhibit A will need to be in this 20 times. Now, I am going to Document>Insert Pages...> (choosing the file) > and then inserting it. I do this whole process 20 times