Execute system command line instructions

Hi,
suppose that my java program has to execute a system command line instrction(let's say dir/p for dos or ls * f or linux)
how can we execute these system command line instructions programmatically from within a java program?
thanks indeed for helping...

i want to thank jfbriere for the usefull link he/she provides me with. 1- He
2- You're welcome :-)

Similar Messages

  • File Adapter 7.11 - set operating system command line dynamically

    Hi,
    is there any way to set the "Operating System Command Line" in the file adapter as ASMA / dynamic attribute?
    I need to set  a command line exec depending on some XSL mapping values.
    thx
    holger

    hi,
    >>>is there any way to set the "Operating System Command Line" in the file adapter as ASMA / dynamic attribute?
    >>>I need to set a command line exec depending on some XSL mapping values.
    think about this approach:
    you put the XSL values into the filename after the real name of the file
    in the batch script you use those values in order to execute a dynamic exe command
    after processing you just change the name of the file in the script by removing the xsl values
    simple ? I think so
    Regards,
    Michal Krawczyk

  • How to run an executable from command-line

    I'm learning how to use the Terminal and I got stuck in a silly thing (I suppose it is). How can I run an executable file from command-line in Terminal?
    For example: I have a file named "Hello" in the folder /sample. If I use the ls command (ls sample), I can see the file Hello. Then I move to the directory (cd /sample) and try to run the file Hello (typing "Hello") but I got "command not found" message.
    If I drag the Hello file from Finder to Terminal and hit Return, it runs perfectly. And if I type the full path to the file (even if I'm already inside its directory), it also runs.
    So, my doubt is if there is any command to run an executable from command-line.
    Thanks

    KJK555 wrote:
    Hi VK:
    Can you enlighten me on why it's neccessary to do the "./" thingy in OS X when in unix/linux
    I never had to resort to doing that?
    Kj
    I took the trouble of reading *man bash* and it explains the issue. to add the current directory to PATH you need to add an empty path to PATH like this
    PATH=$PATH::
    you can add it to ~/.bash_profile so that it's executed automatically when you start bash. I suspect the linux system you are talking about had this set up by default or had it added to PATH in /etc/profile which defines PATH globally.

  • How to execute unix command line from cocoa?

    how to execute unix command line from cocoa?
    for example, if I want to call "ping" from cocoa, how should I do it? and how can I obtain the return value?
    thank you.
    Power G5 Quad Mac OS X (10.4.3)

    The following article may also help:
    http://cocoadevcentral.com/articles/000025.php
    Mihalis.
    Dual G5 @ 2GHz   Mac OS X (10.4.6)  

  • Executing system command thru command line by passing it to a server

    Hello,
    I would like to know if there is any way by which I can call a system command through a java program . This system command takes parameters. If yes then how do i pass these paramaeters. This program will be called thru a sheel scripts and the parameters may vary...

    If I just look at the question in your post, I would say the answer is to call Runtime.getRuntime().exec("the system command"). But the title of the post mentioned passing it to a server; I won't attempt to answer that without knowing what it's all about.

  • Executing System Commands In Java

    Hi,
         I am not sure if this is a bug � or I am just doing this wrong. I have
    written a program to move files into ~/.trash/ . My problem is that this
    works only for files without spaces � but for files with spaces it will
    not work. Some of my code is below.
    I have temporarily uploaded the complete file at
    http://www.geocities.com/carmaski/Remove.java
    public static void main(String args[]) {
    String currDir = System.getProperty("user.dir") + "/";
    String trashDir = "\" \"/home/masca/.trash/";
    String commandString = "";
    for (int i = 0; i < args.length; i++ ) {
    File tmpFile = new File(currDir + args);
    if(tmpFile.exists()) {
    commandString = "mv \"" + currDir + args[i] + trashDir
    + args[i] + getTimeTag() + "\"";
    System.out.println("The command would be -- " +
    commandString);
    try {
    Process p = Runtime.getRuntime().exec(commandString);
    catch (IOException e) {
    e.printStackTrace();
    System.exit(-1);
    As an example I tried � this with a file that has a space � and I get
    the following output.
    The command would be -- mv "/home/masca/WORK/Text File"
    "/home/masca/.trash/Text File_2005.04.17_04hrs:25mins:36secs"
    However the file remains without being moved.
    I cannot understand why the mv command does not work in java. If I
    manually copy this to the command line I can get the file to work. It
    should be noted that this program works perfectly if the file does not
    have a space.
    Regards,
    Rio

    Use File.separator or simply / instead of Windows
    backslashes.
    - SaishI think OP is on a unix machine, and he still needs to escape the spaces. The escape character is, of course, a back-slash.
    Depending on the shell (my experience is with bash), to execute the command mv Test File.txt newTest File.txt, the file names either need to be double-quoted so that the command shell will treat them as a single token (I think that will work), or the spaces need to be escaped (I know that will work). In java, to include a single \ in a literal String, you need to escape the escape character, which is why I think two \\ are needed in the String, so that one will survive to be passed on to the exec command.
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Coldfusion 10: execute as command line

    Using CF10 on a unix system.  Attempting to use cfexecute on perl and batch files do not work but they run fine when executed directly from command line.  The perl and bat file permissions are set so anyone can execute them.  Does anyone know if I make coldfusion execute the perl or bat file as if it was running as a command line?  May need to designate specific user the execute them as.
    <cfexecute name="#EDRSDIR#/uploadconvertwrapper.pl" arguments="#filedirectory# #finalfilename# #dcnflag# #splflag# outputFile="/dev/null" timeOut="0" />
    <cfexecute name="#EDRSDIR#/uploadconvert.bat" argumensts="#filedirectory# #finalfilename# #dcnflag# #splflag# outputFile="/dev/null" timeout="0" />

    What about:
    correcting the spelling of 'arguments';
    dropping the .pl and .bat extensions;
    giving the timeout a value greater than 0;
    adding an error variable which you can output for debugging.
    <cfexecute name="#EDRSDIR#/uploadconvertwrapper" arguments="#filedirectory# #finalfilename# #dcnflag# #splflag# errorVariable="errorOutput" timeout="10" />
    <cfexecute name="#EDRSDIR#/uploadconvert" argumensts="#filedirectory# #finalfilename# #dcnflag# #splflag# errorVariable="errorOutput" timeout="10" />

  • Executing system commands query

    I'm only just starting to program Java although I do have a good grounding in programming other languages so it is probably more a question of familarity, but hopefully someone can answer this problem I am having.
    What I am trying to do is to execute TFTP on a Windows NT machine roughly every 5 seconds to get a file. To do this I have created a thread and within "public void run" I have a loop which contains something along the lines of:
    Runtime.getRuntime().exec( "C:\\WINNT\\system32\\tftp.exe <ipaddress> get <filename>" );
    Where I would specifiy a real IP address and filename.
    I then do a sleep on the current thread to make it pause for a while.
    The good news is it fetches the file every few seconds as I wanted. The bad news is it creates a new TFTP process each time and so it keeps using more and more memory.
    Now I'm sure there are better ways to do this but I am working things out as I go along. The finished program will use an infinite loop which will run out of memory.
    Can anyone recommend a solution or method to do this? Should I not bother with the thread, and what would be the best method to make it pause without killing processor time?
    If possible can anyone mail me directly. Thanks in advance.
    Mark.

    No I must quite specifically use TFTP. The scenario is information is entered via a FORM on a web page. The data is passed from the client to a server where I parse it using perl and write out the data in the necessary form to a file.
    The java file I am writing then runs continually fetching this file every few seconds for another program to read. The other program reads the data every few seconds and uses one of the fields in the file to identify if it has changed since the last time it was fetched, if so it can act on the new data.
    Using TFTP I can call it with a command line function to invoke TFTP to connect and fetch a file in one line. This seems much simpler using an existing executable than hand crafting code to do the same job.
    I've managed to write something in C++ which performs the task. Java seems a bit more ackwared as it discourages you using system commands as it means the code is not portable.
    However I originally wrote this as a Java file to expand my knowledge and as such I would like a proper solution.
    Thanks for the suggestion though. I will have a look just out of curiosity now.
    Mark.

  • How to execute System command through Applet

    Hi all,
    How can I execute a System command through Applet.
    I have written a code Runtime.exec("ls") in my applet but it gives me
    this execption even if I certify the applet ->
    java.security.AccessControlException: access denied (java.io.FilePermission <<ALL FILES>> execute)
         at java.security.AccessControlContext.checkPermission(AccessControlContext.java:272)
         at java.security.AccessController.checkPermission(AccessController.java:399)
         at java.lang.SecurityManager.checkPermission(SecurityManager.java:545)
         at java.lang.SecurityManager.checkExec(SecurityManager.java:802)
         at java.lang.Runtime.exec(Runtime.java:548)
         at java.lang.Runtime.exec(Runtime.java:418)
         at java.lang.Runtime.exec(Runtime.java:361)
         at java.lang.Runtime.exec(Runtime.java:325)
         at Test.init(Test.java:24)
         at sun.applet.AppletPanel.run(AppletPanel.java:344)
         at sun.plugin.navig.motif.MotifAppletViewer.maf_run(MotifAppletViewer.java:123)
         at sun.plugin.navig.motif.MotifAppletViewer.run(MotifAppletViewer.java:119)
         at java.lang.Thread.run(Thread.java:484)
    Thanks,
    Manoj.

    There should be a lesson about this somewhere.
    When you visit a web page, does it ask you if you want to have an applet loaded?
    Answer: No
    So, if you visit a page, and an applet is silently loaded which can then execute commands on your computer, is this good?
    Answer: No
    So why do you want to do this?
    Is it good for anyone?
    I mean, if I want to do "ls", can't I just open a command line? Do I need an applet to do it for me?
    Either you have devious desires or your hacking together something that probably shouldn't be.
    If you want to learn start here:
    http://java.sun.com/docs/books/tutorial/security1.2/index.html
    With the article entitled:
    Quick Tour of Controlling Applets
    Ian

  • Executing multiple command lines in command prompt (windows)

    Hi,
    I am currrently using the command prompt in the windows to try to send a command to the microcontroller that is connected through TCP connection.
    I am able to use the normal cmd.exe to send the command but am unable to send all the command successfully using labview. 
    The Vi. that I am using the the system exec.vi found in labview connectivity section. 
    Basically what I want to send is "telnet A1" in the cmd.exe to establish connection to the microcontroller, followed by "FOR A1 100 GO" which will be intepreted by the microcontroller to make the necessary motion. But currently, the problem is that I can only establish connection using the system exec.vi but am unable to send the second part of the message "FOR A1 100 GO". 
    My command line i tried typing is cme.exe /K telnet A1 & FOR A1 100 GO. it seems that labview is only able to execute the first command part. Is there any other alternatives? 
    Thanks everyone for your help. 
    Solved!
    Go to Solution.

    Hi,
    Thanks for the help, the picture shows 1 of the error which state Error 56, the error occurs occasionally whenever I have used the command prompt to send a message to the microcontroller.
    Alternatively, there are times when no errors occur but my microcontroller does not move as well. It does move if I were to send the command through the cmd prompt.
    And I have attached a picture of my program as well. I am currently using Labview 2010 32bit. Thanks.
    Jh
    Attachments:
    TCP Connection.jpg ‏170 KB
    Error56.png ‏222 KB
    Picomotor_App New v3.0.vi ‏38 KB

  • Launch executable with command line arguments

    I have a programmer that I need to launch in my cvi code.  I tried the system command and lauchexecutable command but cannot get the programmer to lauch correctly.  If I run it from the command prompt or create a windows shortcut it works fine.  Here is the shortcut I created:
    C:\TPD\SAVS20P3\asix\up\up.exe /e c:\tpd\savs20p3\q33.hex/erase /q /p
    I'm trying to run the up.exe software with /e c:\tpd\v20_hex\v20.hex /erase /q /p as the command line paramters.
    I tried the following code which created the above path with command line
     strcpy(filename,"C:\\tpd\\savs20p3\\asix\\up\\up.exe /e c:\\tpd\\savs20p3\\hex_ee\\");   ///e c:\\tpd\\savs20p3\\hex_ee\\"");
      strcat(filename, hfile);//hex file name will change dynamically
      strcat(filename, "/q /p");
    I then tried LaunchExecutable(filename) and system(filename).  The system functions gives an error.  Its trying to lauch the /e c:\tpd\v20_hex\v20.hex file
    any suggestions.  I beieve its a simple syntax error.

    Well, apart evident typos in the code you posted, which is not creating the command line you stated, I can only think that before "/q" you should add a space to separate the option from the filename.
    This code should create the correct command line:
    strcpy (hfile, "c:\\tpd\\v20_hex\\v20.hex");
    strcpy (filename, "C:\\tpd\\savs20p3\\asix\\up\\up.exe /e ");
    strcat (filename, hfile);
    strcat (filename, " /erase /q /p");
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • How to execute system command from java program

    Hi all,
    I want to change directory path and then execute bash and other unix commands from a java program. When I execute them separately, it's working. Even in different try-catch block it's working but when I try to incorporate both of them in same try-catch block, I am not able to execute the commands. The change directory command works but it won't show me the effects of the bash and other commands.
    Suggestions??

    The code I am using is....
    try
    String str="cd D:\\Test";
    Process p=Runtime.getRuntime().exec("cmd /c cd
    "+str);your str string is already having cd in it but again you ar giving cd as part of this command also please check this,i will suggest you to remove cd from str
    Process p1=Runtime.getRuntime().exec("cmd /c mkdir
    "+str+"\\test_folder");you should say mkdir once you change your path,but here you are saying mkdir first and then cd D:\Test(this is because of str)..please check this
    Process p2=Runtime.getRuntime().exec("cmd /c bash");
    Process p3=Runtime.getRuntime().exec("cmd /c echo
    himanshu>name.txt");
    catch(IOException e)
    System.err.println("Error on exec() method");
    e.printStackTrace();
    Message was edited by:
    ragas

  • Execute Process Task :Executing DOS Command lines in Execute Process Task

    Hi All,
    I am trying to sftp files using Tectia Client from my local system. For that I have used the Execute Process Task in SSIS. First I open DOS command and try to instantiate the sftp3.exe.
    Then I write down the below command
    binary
    open username@hostname
    lcd C:\Test
    cd <Destination Path name>
    put test.txt
    How to execute the command in execute process task ?
    help is appreciated
    Thanks

    Hi ConnectDebz,
    According to your description and script example, do you use WinSCP.exe to perform the SFTP files transfer? If so, you should set the Executable of the Execute Process Task to the path of the WinSCP.exe, save the script in a .txt file and set the Argument
    of the Execute Process Task like “/script=C:\Temp\sftploader.txt” (without quotes).
    References:
    http://www.sqlservergeeks.com/blogs/raunak.jhawar/sql-server-bi/395/sql-server-sftp-with-ssis-execute-process-task 
    http://gregcaporale.wordpress.com/2012/02/23/using-sftp-in-sql-server-ssis/ 
    Regards,
    Mike Yin
    If you have any feedback on our support, please click
    here
    Mike Yin
    TechNet Community Support

  • Unable to execute a command line command using Java

    I am trying to run a command to add a group name. It is executed in command prompt of Windows 2003/2000
    Say this is the command I want to execute:
    net localgroup LordSM /add
    Here LordSM is the group name.
    I wrote the following code but it does not seem to work. Please suggest.
    String ABC=Value1TextField.getText();
    Value2Label.setText("Value is now " + ABC);
    // Above is to get value from a JText Field
    // Below is the code to run command for adding a group name to a System.
    String ExecutedCmd = "net localgroup " + ABC + "/add";
    Process p = Runtime.getRuntime().exec(ExecutedCmd);
    BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    // read the output from the command
    System.out.println("Here is the standard output of the command:\n");
    while ((s = stdInput.readLine()) != null)
    { System.out.println(s); }
    // read any errors from the attempted command
    System.out.println("Here is the standard error of the command (if any):\n");
    while ((s = stdError.readLine()) != null)
    { System.out.println(s); }
    I am trying to run a command to add a group name. It is executed in command prompt of Windows 2003/2000
    Say this is the command I want to execute:
    net localgroup LordSM /add
    Here LordSM is the group name.
    I wrote the following code but it does not seem to work. Please suggest.
    String ABC=Value1TextField.getText();
    Value2Label.setText("Value is now " + ABC);
    // Above is to get value from a JText Field
    // Below is the code to run command for adding a group name to a System.
    String ExecutedCmd = "net localgroup " + ABC + "/add";
    Process p = Runtime.getRuntime().exec(ExecutedCmd);
    BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    // read the output from the command
    System.out.println("Here is the standard output of the command:\n");
    while ((s = stdInput.readLine()) != null)
    { System.out.println(s); }
    // read any errors from the attempted command
    System.out.println("Here is the standard error of the command (if any):\n");
    while ((s = stdError.readLine()) != null)
    { System.out.println(s); }
    It does not seem to work means, that no Standard Error is defined, when it executes and group name is not added as well. The following is JUnit Test Result: Hope it gives a better idea of the problem I am facing:
    compile:
    run:
    Here is the standard output of the command:
    Here is the standard error of the command (if any):
    The syntax of this command is:
    NET LOCALGROUP [groupname [/COMMENT:"text"]] [DOMAIN]
    groupname {ADD [/COMMENT:"text"] | /DELETE} [DOMAIN]
    groupname name [...] {ADD | /DELETE} [DOMAIN]
    Got it
    BUILD SUCCESSFUL (total time: 10 minutes 49 seconds)
    I had even tried this:
    Runtime rt =Runtime.getRuntime();
    String[] cmd = new String[3];
    cmd[0] = "cmd.exe";
    cmd[1]="net localgroup";
    cmd[2] =ABC + "/add";
    rt.exec(cmd);
    but again, it does not give any error as such, but it does not create the group name either. Please suggest. We can see the group names that are added on right clicking My Computer Icon and click Manage and then go to User & Group section. On executing either of the code nothing happens.
    Thanks

    Duplicate post:
    http://forum.java.sun.com/thread.jspa?threadID=5203526&messageID=9812067#9812067

  • Executing system commands and capturing results

    How do I get the result of executing a system command using Runtime? For example, if I execute "cmd /c dir", how do I get to the result of the dir command from the Process that is returned?

    Process p = Runtime.getRuntime.exec("...");
    InputStream in = p.getOutputStream();
    // now read the "in" stream just as you would any
    other stream.Slight typo getRuntime(), but it's close...

Maybe you are looking for

  • Mid 2010 Unresponsive

    MacBook Pro Mid 2010 (MacBookPro 6.2) 2.53 GHz Intel Core i5 4 GB 1067 MHz DDR 3 OS X 10.8.5 Mountain Lion Hitachi 500 GB SATA. This machine has worked flawlessly for years. I have about 60GB of data on the drive and backup regularly. Suddenly it has

  • Can IIS be used to proxy to 1 cluster?

    I am running under Windows 2000 AS, with Weblogic 5.2 service pack #6.           I have configured two websites under IIS. Each site uses a directory (2           separate copies) that contains iisproxy.dll and an iisproxy.ini file that is           

  • Photoshop CS6 Hangs at start on Mountain Lion with Macbook Pro Retina

    When opening a clean install of Photoshop CS6, it shows initializing splash screen, then gives me beach ball when Photoshop UI shows... Date/Time:       2013-03-25 11:37:03 -0700 OS Version:      10.8.3 (Build 12D78) Architecture:    x86_64 Report Ve

  • How to get PDF files to open in 1 window, rather than a new window each time

    When opening several PDF files, I find they open up in a new window. Previosuly they opened within the same window. I am using Adobe Reader 9

  • Formatted ipod drive

    I am a new user of iPod nano. I had read up on some forum that the iPod can be used as a mass storage device by adding files through drag and drop. I did exactly that, but then my iPod started getting stuck. I couldn't find a way around aroud it so s