Error in creating a process using runtime class - please help

Hi,
I am experimenting with the following piece of code. I tried to run it in one windows machine and it works fine. But i tried to run it in a different windows machine i get error in creating a process. The error is attached below the code. I don't understand why i couldn't create a process with the 'exec' command in the second machine. Can anyone please help?
CODE:
import java.io.*;
class test{
public static void main(String[] args){
try{
Runtime r = Runtime.getRuntime();
     Process p = null;
     p= r.exec("dir");
     BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
     System.out.println(br.readLine());
catch(Exception e){e.printStackTrace();}
ERROR (when run in the dos prompt):
java.io.IOException: CreateProcess: dir error=2
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Win32Process.java:63)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:550)
at java.lang.Runtime.exec(Runtime.java:416)
at java.lang.Runtime.exec(Runtime.java:358)
at java.lang.Runtime.exec(Runtime.java:322)
at test.main(test.java:16)
thanks,
Divya

As much as I understand from the readings in the forums, Runtime.exec can only run commands that are in files, not native commands.
Hmm how do I explain that again?
Here:
Assuming a command is an executable program
Under the Windows operating system, many new programmers stumble upon Runtime.exec() when trying to use it for nonexecutable commands like dir and copy. Subsequently, they run into Runtime.exec()'s third pitfall. Listing 4.4 demonstrates exactly that:
Listing 4.4 BadExecWinDir.java
import java.util.*;
import java.io.*;
public class BadExecWinDir
public static void main(String args[])
try
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("dir");
InputStream stdin = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(stdin);
BufferedReader br = new BufferedReader(isr);
String line = null;
System.out.println("<OUTPUT>");
while ( (line = br.readLine()) != null)
System.out.println(line);
System.out.println("</OUTPUT>");
int exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);
} catch (Throwable t)
t.printStackTrace();
A run of BadExecWinDir produces:
E:\classes\com\javaworld\jpitfalls\article2>java BadExecWinDir
java.io.IOException: CreateProcess: dir error=2
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Unknown Source)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at BadExecWinDir.main(BadExecWinDir.java:12)
As stated earlier, the error value of 2 means "file not found," which, in this case, means that the executable named dir.exe could not be found. That's because the directory command is part of the Windows command interpreter and not a separate executable. To run the Windows command interpreter, execute either command.com or cmd.exe, depending on the Windows operating system you use. Listing 4.5 runs a copy of the Windows command interpreter and then executes the user-supplied command (e.g., dir).
Taken from:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

Similar Messages

  • Issue regarding creating a process using Runtime in Windows 2003.

    Hi all..
    I need to resolve a small issue related to execute an external program using runtime execution method. But when i deploy the code in websphere application server 6.1V in windows 2003 server operating system, it is starting a process with min priority and not executing even i specified waitfor method.
    The code is like below.
    try{
    Process p = Runtime.getRuntime().exec("C:\\CopyImages.exe "+toWrite);
    int ep = p.waitFor();
    System.out.println("process "+ep);
    catch(Exception e)
    e.printStackTrace();
    Please help me in resolving this issue. The above code is working in my IDE which is in Window XP but when i port it in application server in windows2003 i'm getting this issue.

    hi..
    it is a typo error. i've given the slashes with that.
    but still getting the problem.

  • Error while creating an Index in SP14..Please help..  :(

    Hello All,
    Im working on SP14.
    Got an error as below while creating an Index:
    " <b>Index could not be created; creating index failed: general configuration error (Errorcode 2030)"</b>
    Whats wrong..?
    Please help.
    Awaiting Reply.
    Thanks and Warm Regards,
    Ritu R Hunjan

    Hi Ritu & Subrato,
    I'm affraid Errorcode 2030 is related to TREX user administrative rights in the OS.
    Please take a look at this thread and the suggestions give there to fix your problem:
    Index creation failure and other problems
    Hope this helps,
    Robert

  • Execute an external program using Runtime class

    How to execute an external java program using Runtime class?
    I have used ,
    Process p=Runtime.getRuntime().exec("c:/j2sdk1.4.0/bin/helloworld.java ");
    But it throws a runtime IOException error:2 or error:123.
    Help me with the code. Thanks in advance.

    Create Runtime Object and attach to system process.Try this code
    import java.io.*;
    public class ExecuteExternalApp {
      public static void main(String args[]) {
                try {
                    Runtime rt = Runtime.getRuntime();
                    //Process pr = rt.exec("cmd /c dir");
                    Process pr = rt.exec("c:\\ yamessenger.exe"); //give a valid exe file
                    BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
                    String val=null;
                    while((val=input.readLine()) != null) {
                        System.out.println(val);
                    int exit = pr.waitFor();
                    System.out.println("Exited with error code "+exit);
                } catch(Exception e) {
                    System.out.println(e.toString());
                    e.printStackTrace();
    }Edited by: anishtomas on Feb 3, 2009 9:34 PM
    Edited by: anishtomas on Feb 3, 2009 9:37 PM

  • Executing a command using Runtime Class

    How to execute a command on a differnet machine with different ipaddress using Runtime Class
    My code is
    String[] cmd = new String[3];
    cmd[0] = "192.1...../c:/WINNT/system32/cmd.exe" ;
    cmd[1] = "/C" ;
    cmd[2] = args[0];
    Runtime rt = Runtime.getRuntime();
    System.out.println("Execing " + cmd[0] + " " + cmd[1]
    + " " + cmd[2]);
    Process proc = rt.exec(cmd);
    // any error???
    int exitVal = proc.waitFor();
    System.out.println("ExitValue: " + exitVal);
    This is not Working

    I have same issue. Actually when I use cmd.exe /c set in java code and if I run the java code in DOS propmt, it retrieves all latest user Environment variable values. But if I run the code in windows batch file, it is not retrieveing the latest user environment values until I reboot my computer, Do you know how to get user environment value with out rebooting machine??????

  • Error testing my Business Process using Application View Control

    Hi there
    i'm using WLS 8.1 SP 4 and Sap Adapter 8.1
    I already could build my app view in app integration design console I can testing and everything works fine.
    I'm using adpater to sap and i able to see the results from SAP
    Now,,, i alreade created my app view control in order to use it in my business process but i get the following error:
    <Mar 3, 2006 10:34:53 AM CST> <Warning> <WLW> <000000> <Id=appViewControlTPA:0;
    Method=jpd.TPAAppView.serviceTPACompanyList(); Failure=com.bea.wlai.client.Appli
    cationViewException: Error invoking service 'serviceTPACompanyList' on Applicati
    onView 'TPAAppView': com.bea.xml.XmlException: Top level QName: {wlai/TPAAppView
    serviceTPACompanyListBAPI_COMPANYCODE_GETLIST_request}CompanyCode.GetList.Resp
    onse does not match the expected top level qname: {wlai/TPAAppView_serviceTPACom
    panyList_BAPI_COMPANYCODE_GETLIST_response}CompanyCode.GetList.Response in schem
    a type
    com.bea.xml.XmlException: Top level QName: {wlai/TPAAppView_serviceTPACompanyLis
    t_BAPI_COMPANYCODE_GETLIST_request}CompanyCode.GetList.Response does not match t
    he expected top level qname: {wlai/TPAAppView_serviceTPACompanyList_BAPI_COMPANY
    CODE_GETLIST_response}CompanyCode.GetList.Response in schema type
    at com.bea.wli.variables.XmlObjectVariableFactory.createProxy(Lcom.bea.w
    li.variables.ProcessXML;Ljava.lang.Class;Z)Lcom.bea.xml.XmlObject;(XmlObjectVari
    ableFactory.java:137)
    at com.bea.wli.variables.XmlObjectVariableFactory.createProxy(Lcom.bea.w
    li.variables.ProcessXML;Ljava.lang.Class;)Lcom.bea.xml.XmlObject;(XmlObjectVaria
    bleFactory.java:199).............
    these are my schemas:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema elementFormDefault="unqualified"
    targetNamespace="wlai/TPAAppView_serviceTPACompanyList_BAPI_COMPANYCODE_GETLIST_request"
    xmlns="wlai/TPAAppView_serviceTPACompanyList_BAPI_COMPANYCODE_GETLIST_request"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:complexType name="BAPI0002_1">
    <xsd:sequence>
    <xsd:element name="COMP_CODE">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:maxLength value="4"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="COMP_NAME">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:maxLength value="25"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="CompanyCode.GetList">
    <xsd:complexType>
    <xsd:all>
    <xsd:element minOccurs="0"
    name="COMPANYCODE_LIST">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element maxOccurs="unbounded"
    minOccurs="0"
    name="item"
    type="BAPI0002_1"/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:all>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema elementFormDefault="unqualified"
    targetNamespace="wlai/TPAAppView_serviceTPACompanyList_BAPI_COMPANYCODE_GETLIST_response"
    xmlns="wlai/TPAAppView_serviceTPACompanyList_BAPI_COMPANYCODE_GETLIST_response"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:complexType name="BAPIRETURN">
    <xsd:sequence>
    <xsd:element name="TYPE">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:maxLength value="1"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="CODE">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:maxLength value="5"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="MESSAGE">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:maxLength value="220"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="LOG_NO">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:maxLength value="20"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="LOG_MSG_NO">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:maxLength value="6"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="MESSAGE_V1">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:maxLength value="50"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="MESSAGE_V2">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:maxLength value="50"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="MESSAGE_V3">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:maxLength value="50"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="MESSAGE_V4">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:maxLength value="50"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="BAPI0002_1">
    <xsd:sequence>
    <xsd:element name="COMP_CODE">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:maxLength value="4"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="COMP_NAME">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:maxLength value="25"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="CompanyCode.GetList.Response">
    <xsd:complexType>
    <xsd:all>
    <xsd:element minOccurs="0"
    name="RETURN"
    type="BAPIRETURN"/>
    <xsd:element minOccurs="0"
    name="COMPANYCODE_LIST">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element maxOccurs="unbounded"
    minOccurs="0"
    name="item"
    type="BAPI0002_1"/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:all>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>
    and this is my xml i'm using as a request:
    <?xml version="1.0" encoding="UTF-8"?>
    <n1:CompanyCode.GetList xmlns:n1="wlai/TPAAppView_serviceTPACompanyList_BAPI_COMPANYCODE_GETLIST_request" xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="wlai/TPAAppView_serviceTPACompanyList_BAPI_COMPANYCODE_GETLIST_request">
         <COMPANYCODE_LIST>
              <item>
                   <COMP_CODE/>
                   <COMP_NAME/>
              </item>
         </COMPANYCODE_LIST>
    </n1:CompanyCode.GetList>
    i do not what it is wrong and i don't understand why i can test my app view since app int desing console succesfully but i get an error running my business process using workshop
    any idea?

    Try to send some valid data in COMP_CODE.
    It seems that SAP is returning some reply which is not fitting your response Schema.
    SAP Call is made and problem is in generating response document.
    Use the design console to test the view again. and try to see the XML resquest document and response document. Compare your request xml with that in design console.

  • Creating a triangle using polygon class problem, URGENT??

    Hi i am creating a triangle using polygon class which will eventually be used in a game where by a user clicks on the screen and triangles appear.
    class MainWindow extends Frame
         private Polygon[] m_polyTriangleArr;
                       MainWindow()
                              m_nTrianglesToDraw = 0;
             m_nTrianglesDrawn = 0;
                             m_polyTriangleArr = new Polygon[15];
                             addMouseListener(new MouseCatcher() );
            setVisible(true);
                         class MouseCatcher extends MouseAdapter
                             public void mousePressed(MouseEvent evt)
                  Point ptMouse = new Point();
                  ptMouse = evt.getPoint();
                if(m_nTrianglesDrawn < m_nTrianglesToDraw)
                                int npoints = 3;
                        m_polyTriangleArr[m_nTrianglesDrawn]
                      = new Polygon( ptMouse[].x, ptMouse[].y, npoints);
    }When i compile my code i get the following error message:
    Class Expected
    ')' expectedThe two error messages are refering to the section new Polygon(....)
    line. Please help

    Cannot find symbol constructor Polygon(int, int, int)
    Can some one tell me where this needs to go and what i should generally
    look like pleaseI don't think it is a good idea to try and add the constructor that the compiler
    can't find. Instead you should use the constructor that already exists
    in the Polygon class: ie the one that looks like Polygon(int[], int[], int).
    But this requires you to pass two int arrays and not two ints as you
    are doing at the moment. As you have seen, evt.getPoint() only supplies
    you with a single pair of ints: the x- and y-coordinates of where the mouse
    button was pressed.
    And this is the root of the problem. To draw a triangle you need three
    points. From these three points you can build up two arrays: one containing
    the x-coordinates and one containing the y-coordinates. It is these two
    arrays that will be used as the first two arguments to the Polygon constructor.
    So your task is to figure out how you can respond to mouse presses
    correctly, and only try and add a new triangle when you have all three of its
    vertices.
    [Edit] This assumes that you expect the user to specify all three vertices of the
    triangle. If this isn't the case, say what you do expect.

  • FTP using Runtime class ...Please Help ??

    Hi,
    I am trying to ftp a file programatically.
    I am trying to use Runtime class but facing problems
    in it.This is what I am trying to do :
    Runtime rr = Runtime.getRuntime();
    String[] cmds = new String[2];
    cmds[0]="username=rahmed";
    cmds[1]="password=prpas";
    try{
    Process p = rr.exec("ftp 192.168.1.18",cmds);     
    rr.exec("put vv.txt");
    This does not work ??
    Is there any way to make it work ? Or is there any
    other way to ftp a file programatically ??
    Thanks in adavance..
    Regards
    Rais

    Under Linux/Unix at least, it is good to use the switches -n and -i with the ftp client acually meant for intercative usage.
    -i Turns off interactive prompting during multiple file transfers.
    -n Restrains ftp from attempting ``auto-login'' upon initial connection.
    I do "user <myuser> <mypassword>" then from the script.
    I am happily using ftp this way from shell-scripts in my projects.
    scp is however better than ftp: it does not send plain text passwords over the net, it support key-based login, its encrypts the data.

  • Spawn a java process using runtime.exec() method

    Hi,
    This is my first post in this forum. I have a small problem. I am trying to spawn a java process using Runtime.getRuntime().exec() method in Solaris. However, there is no result in this check the follwoing program.
    /* Program Starts here */
    import java.io.*;
    public class Test {
    public static void main(String args[]) {
    String cmd[] = {"java", "-version"};
    Runtime runtime = Runtime.getRuntime();
    try{
    Process proc = runtime.exec(cmd);
    }catch(Exception ioException){
    ioException.printStackTrace();
    /* Program ends here */
    There is neither any exception nor any result.
    The result I am expecting is it should print the following:
    java version "1.4.0"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
    Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
    Please help me out in this regard
    Thanks in advance
    Chotu.

    Yes your right. It is proc.getInputStream() or proc.getErrorStream(). That is what I get for trying to use my memory instead of looking it up. Though hopefully the OP would have seen the return type of the other methods and figured it out.

  • Error in creating OUI Process()

    Hi,
    When try to install Oracle 8i on Redhat Linux
    its giving an error
    initializing Java Virtual Machine from
    /usr/local/jre/bin/jre please wait ....
    Error in create OUI process();-1
    :permission denied.
    I would like to know what previleages the user should have to install the Oracle 8i.
    Thanks,
    Kishor

    You are installing Oracle using the ./runinstaller... You have to go to ../install/linux/runIns.sh
    That should work...
    I might have a few things mispelled because I don't have my Linux box here... In any case, look for the runIns.ah file and make sure you unset CLASSPATH!!!
    -Darrin

  • Error while creating resource group using non-globalzones.

    Dear all,
    Hi techs please guide me how to create failover resource group in nongloablzones.
    I'm getting error while creating resource group using non-globalzones.
    My setup:
    I have two node cluster running sun cluster 3.2 configured and running properly.
    node1: sun5
    nide2: sun8
    I have create non-globalzone "zone1" in node:sun5
    I have create non-globalzone "zone2" in node:sun8
    node:sun5# clrg create -n sun5:zone1,sun8:zone2 zonerg
    *(C160082) WARNING: one or more zones in the node list have never been fully booted in the cluster mode,verify that correct zone name was entered.*
    kindly guide me how to create Apache resource group using non-glabalzones, i'm new to sun cluster 3.2. please guide me step by step information.
    Thanks in advance,
    veera
    Edited by: veeraa on Dec 19, 2008 1:54 AM

    Hi Veera,
    Actually you are getting a warning message where one of two things could have happened. Either you specified an incorrect zone name or one of the zones has not been fully booted. It's likely that you haven't booted the zones, so please follow this:
    zoneadm list -iv
    If zone1 or zone2 are not running then boot and configure them
    zoneadm -z <zone> boot
    zlogin -C <zone>
    After that you can continue to follow the step by step instructions at
    http://docs.sun.com/app/docs/doc/819-2975/chddadaa?a=view
    These may also help
    http://blogs.sun.com/Jacky/entry/a_simple_expample_about_how
    http://blogs.sun.com/SC/en_US/entry/sun_cluster_and_solaris_zones
    Regards
    Neil

  • Oracle Universal Installer - Error En Create OUI Process (): 5

    When I want to install ODAC (Oracle Data Provider) for Visual Studio gives me the following error:
    Oracle Universal Installer - Error En Create OUI Process (): 5
    Thank You ..

    What version of client are you trying to install? I'd go with 11.2.0.2 to rule out any known issues with the OUI.
    11202 is available on MOS. If you don't have Oracle Support to be able to access MOS, 11201 is available in the downloads section on OTN.
    Greg

  • Error : J_2IRG1BAL, Create data processing Function module

    Sap Experts,
    when i go to se11 in which have given table name: J_2IRG1BAL, than i gone menu bar click on utilities select the table contents
    click on create entries button.
    1) Error Message : Create data processing function module
    2) This table Relevant to RG1 Updation
    3) Due to this error I am not able to upload the opening stock of finished material manuaaly
    4) What are the actions need to be done to rectify the above error.
    Regards,
    Prabhakar

    Hi
    Ask your ABAPER to create the maintainence view of the table
    regards
    Sanil Bhandari

  • Error: "AppStore could not process your request. Please check your AppStore account details

    Error: "AppStore could not process your request. Please check your AppStore account details"
    I changed my card details for my apple id since then i have been getting this error  mesg whenever i try to download a paid app - or make payments for existing apps.
    I created a new apple id and tried using that- but the error still pops up.

    I believe that something is wrong with the App Store on Apple's end.
    My issue is that my purchase history is completely blank when it shouldn't be.
    I believe it's an issue on Apple's end because the same thing occurs on other iPads in the house &amp; on my iPhone.
    Sorry I can't be of more help, I'd just say wait it out.
    -Chris

  • We're sorry, an error has occurred while processing the request. Please try again. that error comes when i registred the apple care protection plan plzz suggestion me

    We're sorry, an error has occurred while processing the request. Please try again. that error comes when i registred the apple care protection plan plzz suggestion me

    Call AppleCare.

Maybe you are looking for