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

Similar Messages

  • 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) {
        }

  • Execute .cmd command file on application server

    Hi all,
    I have written a dosprogram with .cmd trigger that i want to execute via an ABAP statement. Is there a function module that can execute this specific command file on the server?
    If so, can someone send an example of such a coding?
    Thanks in advance for your reply!
    Best regards,
    F. Geldof
    Moderator message: FAQ, please search for available information before asking.
    locked by: Thomas Zloch on Sep 14, 2010 11:46 AM

    Hi F. Geldof,
    - Create a command in SM69
    - Execute the command using the function module: SXPG_COMMAND_EXECUTE
    [Refer to this program|http://saplab.blogspot.com/2007/10/sample-abap-program-to-execute-unix.html]
    Thanks,
    Duy

  • Executing multiple commands with sudo fails

    Hi,
    We're having trouble with sudo and bash.  When we want to execute multiple commands and there are spaces, the commands don't run.  Here's an example of what works:
    [root@erpapp1-prod ~]# sudo -i -u oracle bash -c 'ls;pwd'
    In this case, I get a listing of the files in /home/oracle followed by the current directory of /home/oracle.
    Here's an example of what DOESN'T work:
    [root@erpapp1-prod ~]# sudo -i -u oracle bash -c 'ls; pwd'
    Notice the space before "pwd".  In this case, all I get is the listing of files in /home/oracle.
    Caveat:  I'm a real beginner with Linux.  I've compared many of the files (/home/oracle/.bash_profile, /home/oracle/.bashrc, /etc/bashrc, /etc/profile) from this server to another where we don't have issues and, other than some logic being in different order, don't see much of a difference.  Again, very beginner here.
    Any ideas?  Thanks!
    Todd

    What shows up as a space may not necessarily be a space. For instance, it could be some control character like a newline, which might interfere with the execution. For example:
    $ test=`echo -e "test;\ntest"`
    $ echo $test
    test; test
    $ echo "$test"
    test;
    test
    Here is another example:
    # test=`echo -e "ls;\npwd"`
    # su - oracle -c "$test"
    oradiag_oracle
    /home/oracle
    # su - oracle -c $test
    oradiag_oracle
    I cannot guess how you construct the command list. Perhaps the problem is a text files that was created under Windows and copied as binary to Linux, or a shell script using a different IFS environment variable, etc.
    Personally I would use a different approach. From a security standpoint it is a bad idea to use passwords at the command prompt because every user can see them using the ps -ef  output.

  • How to create a activex control to execute cmd.exe with parameters?

    Hi,
    Is there any way to execute a cmd.exe on client side using activex.
    currently i am using vs-2013
    Please help i have no idea about activex control.
    Pawan

    No, there is certainly no server side setting that will allow you to do this. Please refer to the following links for more information:
    http://stackoverflow.com/questions/1791511/run-exe-from-client-side
    http://stackoverflow.com/questions/5787200/how-to-open-command-prompt-from-my-application-client-side
    http://p2p.wrox.com/javascript-how/24362-how-call-shell-cmd-open-exe-clientside.html
    Please remember to mark helpful posts as answer and/or helpful.

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

  • Haviing double quotes show up when executing a command with a variable

    I am trying to run a command that requires double quotes to be part of it. For example:
    $adddiskname = "Harddisk5"
    "$adddiskname(No
    Signature)"
    only gives the output of
    Hardisk5 (No Signature)
     but I need it to look this when it runs:
    "Harddisk5 (No Signature)"
    Here is the command line I have now:
    $adddiskname = "Harddisk5" Start-Process-FilePath'C:\Program
    Files\Veritas\Veritas Volume Manager\vxdisk'-ArgumentList"-f","sig","$adddiskname(Not
    Signature)"-Wait
    Any help would be great.
    Thanks,

    The entire string needs to be in the Quotes, so when the command is run, it shows the (No Signature) as well.
    Example:
    "Harddisk5 (No Signature)" is the end result.
    Okay:
    $addDiskName = 'Harddisk5'
    "`"$addDiskName (No Signature)`""
    Don't retire TechNet! -
    (Don't give up yet - 13,225+ strong and growing)

  • How to use Runtime execute DOS command?

    Hello,
    I can not use Runtime class execuste Dos command such as copy and dir.
    Is there any suggestion?
    Thanks in advance.

    execute the command with cmd /c (winNT, win2k) or command /c (win9x). Example: "cmd /c dir"
    details: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Sudo can't execute some commands[SOLVED]

    Hi Archers,
    I am using sudo and disable root account. There is some problems with sudo such as the following commands:
    #sudo echo "1234"  >/etc/rc.local
    # sudo cd /root
    I can't execute these commands with sudo, instead i have to login as root and execute the commands. So the question is how can I solve these problems?
    The Second issue is how can I give certain user the commands that they can execute. For example, user A is only allowed to use "ls" commands and not any other commands?
    Cheers
    Last edited by hungsonbk (2008-11-17 02:02:29)

    You can't use those commands because it aren't real commands, it are shell builtins and they are ran by your shell which is ran by your regular user.
    sudo echo foo > bar
    This runs the "echo" binary as root but the ">" part is handled by the shell, appropriate way to handle this:
    echo foo|sudo tee bar
    cd wont work neither, if it did you could cd to a directory you don't have permissions to and then you would be in their as regular user, unable to do anything... You should just work from outside /root or use sudo -s.
    For the user thing: man sudoers.
    Last edited by Ramses de Norre (2008-11-15 16:52:55)

  • How to run cdb -c with a command that contains paths with spaces?

    CDB has a -c command line option that runs a specified command, sort of like
    cmd -c, I suppose. Here's what I need to run:
    cdb.exe -c "!itoldyouso \"c:\Program Files (x86)\My Software\1.exe\" \"c:\Development\my-software\bin\1.pdb\";q" "notepad.exe"
    Note that here I've tried escaping quotes around paths with \. No luck. I've also tried
    ^ and """ (triple quote). All I get is this:
    0:000> cdb: Reading initial command '!itoldyouso "c:\Program Files (x86)\My Software\1.exe" "c:\Development\my-software\bin\1.pdb";q'
    c:Program - ignored. The input name/address could not be resolved to a loaded module.
    Files - ignored. The input name/address could not be resolved to a loaded module.
    (x86)My - ignored. The input name/address could not be resolved to a loaded module.
    Software1.exe - ignored. The input name/address could not be resolved to a loaded module. Could not find module c:program ^ Extra character error in '!itoldyouso "c:\Program Files (x86)\My Software\1.exe" "c:\Development \my-software\bin\1.pdb";q'
    The command is passed to CDB correctly, but CDB itself doesn't know how to parse quotes.

    Hmm,
    !itoldyouso with spaces in path does not even work, when started inside cdb or windbg for me.
    But something like this reports success:
    cdb.exe -c ".reload /f /i \"'C:\Users\sammy\Documents\Visual Studio 2010\Projects\DebuggerStub\Debug\DebuggerStub.
    exe'=0x6000000,0x1b000\"" notepad.exe
    Microsoft (R) Windows Debugger Version 6.3.9431.0 X86
    Copyright (c) Microsoft Corporation. All rights reserved.
    CommandLine: notepad.exe
    ************* Symbol Path validation summary **************
    Response Time (ms) Location
    OK C:\Users\sammy\Documents\Visual Studio 2010\Projects\DebuggerStub\De
    bug
    OK C:\Windows\symbols\dll
    Deferred srv*C:\Symbols\MsSymbols*http://msdl.microsoft.com/download/symbols
    Symbol search path is: C:\Users\sammy\Documents\Visual Studio 2010\Projects\DebuggerStub\Debug;C:\Windows\symbols\d
    ll;srv*C:\Symbols\MsSymbols*http://msdl.microsoft.com/download/symbols
    Executable search path is:
    ModLoad: 007c0000 007e8000 notepad.exe
    ModLoad: 77540000 77668000 ntdll.dll
    ModLoad: 77460000 7753d000 C:\Windows\system32\kernel32.dll
    ModLoad: 75c70000 75d36000 C:\Windows\system32\ADVAPI32.dll
    ModLoad: 75f60000 76022000 C:\Windows\system32\RPCRT4.dll
    ModLoad: 75ed0000 75f1c000 C:\Windows\system32\GDI32.dll
    ModLoad: 77680000 7771d000 C:\Windows\system32\USER32.dll
    ModLoad: 761d0000 7627a000 C:\Windows\system32\msvcrt.dll
    ModLoad: 77720000 77793000 C:\Windows\system32\COMDLG32.dll
    ModLoad: 75c10000 75c69000 C:\Windows\system32\SHLWAPI.dll
    ModLoad: 749c0000 74b5e000 C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.6002.1830
    5_none_5cb72f2a088b0ed3\COMCTL32.dll
    ModLoad: 76920000 77431000 C:\Windows\system32\SHELL32.dll
    ModLoad: 6f750000 6f792000 C:\Windows\system32\WINSPOOL.DRV
    ModLoad: 76310000 76455000 C:\Windows\system32\ole32.dll
    ModLoad: 76280000 7630e000 C:\Windows\system32\OLEAUT32.dll
    (fc8.1738): Break instruction exception - code 80000003 (first chance)
    eax=00000000 ebx=00000000 ecx=0015fa34 edx=775a5b44 esi=fffffffe edi=00000000
    eip=775886ce esp=0015fa4c ebp=0015fa7c iopl=0 nv up ei pl zr na pe nc
    cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
    ntdll!DbgBreakPoint:
    775886ce cc int 3
    0:000> cdb: Reading initial command '.reload /f /i "'C:\Users\sammy\Documents\Visual Studio 2010\Projects\DebuggerS
    tub\Debug\DebuggerStub.exe'=0x6000000,0x1b000"'
    *** WARNING: Unable to verify timestamp for 'C:\Users\sammy\Documents\Visual Studio 2010\Projects\DebuggerStub\Debu
    g\DebuggerStub.exe'
    0:000> lm
    start end module name
    007c0000 007e8000 notepad (deferred)
    06000000 0601b000 DebuggerStub M (private pdb symbols) c:\users\sammy\documents\visual studio 2010\projects\debuggerstub\debug\DebuggerStub.pdb
    6f750000 6f792000 WINSPOOL (deferred)
    So a backslash looks not so bad, else one can try to use a script-file with "-c" arg. 
    With kind regards

  • 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

  • Error when I execute an application with the java command in a DOS prompt

    Hi:
    I have a trouble. I edit the most simple program in Java: hello.java
    In DOS prompt, I compile the program. The result is the file hello.class
    c:\> javac hello.java
    However, I try to execute this program with the command java
    c:\> java hello
    and the DOS prompt send me an error like this: Java.exe has a problem and must be closed.
    I press the option "Don't send". After this, the DOS prompt returns empty and it doesnt execute the application:
    c:\>
    By the way, in an IDE editor like Gel, the file hello.java is compiled and executed correctly without problems.
    I edited other simple Java files, I compiled them succesfully and I can't run them in a DOS pormpt. The result is the same dialog box: "Java.exe has a problem and must be closed".
    The question is: Why don't these programs run in a DOS prompt?
    My Operating System is Microsoft Windows XP and the Java compiler version is: 1.6.0_13
    Thanks in advanced.

    Hi again:
    What happens when you type "java -version"?
    Answer:
    java version "1.2"
    Classic VM (build JDK-1.2-V, native threads)
    What is the value of your %PATH%?
    Answer:
    Path=E:\oracle\product\10.2.0\db_1\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Archivos de programa\Archivos comunes\Adaptec Shared\System;C:\Archivos de programa\Executive Software\DiskeeperLite\;C:\Archivos de programa\QuickTime\QTSystem\;C:\Archivos de programa\Java\jdk1.6.0_13\bin;C:\Archivos de programa\Microsoft SQL Server\80\Tools\Binn\;e:\Microsoft SQL Server\90\Tools\binn\;C:\BITWARE\;C:\Archivos de programa\Archivos comunes\Ahead\Lib\
    PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
    Have you considered running Linux?
    Answer: No, because Linux is more complex.
    Additional information:
    My Operating System is: Microsoft Windows XP Profesional Version 2002, Service Pack 3, running on an Intel Pentium 4, CPU 2.4 Ghz, RAM: 2.23 Gb

  • 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).

  • Executing .cmd with Runtime.exec()

    I'm trying to run a file with the following cod:
    Runtime rt = Runtime.getRuntime();
    String[] command = {"cmd.exe", "/c", "start", "c:\\Documents and Settings\\Rahul Shroff\\Desktop\\svn\\trunk\\c\\rahul_facedetect.cmd"};
    try{
             Process proc = rt.exec(command);
    catch(Exception e) {System.out.println("error with proc" + e.getMessage());}With the code, a command prompt is opened, but my .cmd file is not. Does anyone know how to fix this? Please don't send me a link to the "When Runtime.exe() Won't" ; I have already looked through this. Thanks!

    Okay, I tried that, and the code compiled fine, but I got this runtime error:
    error with procCreateProcess: "C:\Documents and Settings..." error = 123
    My code is :
    Runtime rt = Runtime.getRuntime();
        String[] command = {"C:\\Documents and Settings\\Rahul Shroff\\Desktop\\svn\\trunk\\c\\rahul_facedetect.exe --cascade=C:\\Documents and Settings\\Rahul Shroff\\Desktop\\svn\\trunk\\OpenCV\\data\\haarcascades\\haarcascade_frontalface_alt.xml"};
        try{
             Process proc = rt.exec(command);
             System.out.println("tried to execute .cmd");
        catch(Exception e) {System.out.println("error with proc" + e.getMessage());}
      }I am sure that the command C:\Documents and Settings... works; I've tried it separately in a command prompt. Any suggestions? Thanks for the help!

  • [SOLVED] problem with spaces and ls command in bash script

    I am going mad with a bash script I am trying to finish. The ls command is driving me mad with spaces in path names. This is the portion of my script that is giving me trouble:
    HOMEDIR="/home/panos/Web Site"
    for file in $(find "$HOMEDIR" -type f)
    do
    if [ "$(dateDiff -d $(ls -lh "$file" | awk '{ print $6 }') "$(date +%F)")" -gt 30 ];
    then echo -e "File $file is $(dateDiff -d $(ls -lh "$file" | awk '{ print $6 }') "$(date +%F)") old\r" >> /home/panos/scripts/temp;
    fi
    done
    The dateDiff() function is defined earlier and the script works fine when I change the HOMEDIR variable to a path where there are no spaces in directory and file names. I have isolated the problem to the ls command, so a simpler code sample that also doesn't work correctly with path names with spaces is this:
    #!/bin/bash
    HOMEDIR="/home/panos/test dir"
    for file in $(find "$HOMEDIR" -type f)
    do
    ls -lh "$file"
    done
    TIA
    Last edited by panosk (2009-11-08 21:55:31)

    oops, brain fart. *flushes with embarrassment*
    -- Edit --
    BTW, for this kind of thing, I usually do something like:
    find "$HOMEDIR" -type f | while read file ; do something with "$file" ; done
    Or put those in an array:
    IFS=$'\n' ; files=($(find "$HOMEDIR" -type f)) ; unset IFS
    for file in "${files[@]}" ; do something with "$file" ; done
    The later method is useful when elements of "${files[@]}" will be used multiple times across the script.
    Last edited by lolilolicon (2009-11-09 08:13:07)

Maybe you are looking for

  • How do i manually block certain sites or pop-ups? (if i know or dont know site url)

    well lets see i have a pop-up block like everyone else in that has firefox it block pop-up but i still have those few that make it past that is where my rage gets up and i want to troll the crap out of the little mother fu&%ers how can you block them

  • Out bound Idoc for IE01

    Dear All I am trying to send the equipment details via idoc from SAP to outside, Could you please help me in getting to know what standard idoc or message type I can use and where I can trigger the idoc. Amol Sonaikar

  • CORBA IDL "pragma ID" not solving problem

    Similar to "CORBA Bug?", I get the stacktrace that is listed at the end of this note. I have put "pragma ID..." for typedefs, structs and interfaces in my idl file. I did nothing else to the code. The same errors were generated, so I assume the "prag

  • How can I use either the contact center reporting or CAR to identify calls transferred from agents to other extensions?

    We are not to the call manager and I am trying to find a way to report calls that were received to our customer service agents though the call queue but were subsequently transferred to an extension out side of the queue.  With our implementation we

  • Mic but no sound

    I've hooked an M-Audio mic up to my Mac and was going to record voice but keep getting a message saying 'Audio record path not found! Please set it in the following dialog!"  Also, I cannot hear the jingle through my headphones. What does this mean?