UNIX Problem with method Runtime exec(String[],String[],File)

Hello !!
i'm french
scuse my english
I got a probleme with method exec(String[],String[],File) of Runtime Class
i don't have any probleme when my program runs on Windows NT but the same program on UNIX doesnt execute my command..
When i use exec(String[]) methode i dont have this problem ...but i need the second one methode because i have to execute my command in a different directory than the JAVA program.
I need that results of this command are placed in this drectory so that i can't use an exex() like that :
exemple with a perl :
"perl /toto/titi/hello.pl"
I want to execute this :
"perl hello.pl" (and hello.pl is placed in /toto/titi)
Conclusion :
the exec(String[],String[],File) solution is ok with NT ...
but with UNIX ????
Is there other solution ??
Should i do a "cd" command before my execution ? how can i do this ??
Thanks !!!!

Could you post your source code (only relevant part)
Raghu

Similar Messages

  • Problem with method Runtime.exec()

    i wrote this simple line, in a servlet:
    Runtime.getRuntime().exec(myCommand);
    if i run this servlet in the OC4j included whith jdeveloper all works well...but if i run the same servlet in the Application server, the command is not executed...why????
    is it a security issue?
    please help me..

    Stefano, can you take a look at the application server log files to see if there is any related information that tells what was happening? What is better, can you try catching the standout and standerr of your command as what is done in the following message?
       Re: javac not found on UNIX AIX runnig Oracle AS 9.0.4
    Please tell me if you have any new findings then.

  • Problem in using runtime.exec()

    Hi all,
    I am having a problem with the runtime.exec method.I am trying to execute linux commands using this method.For most of the commands it works fine.But when i tried to change the user with the su command in linux my program hung up.So please help me to get around this.any help would be highly appreciable..
    I am pasting the code..
    <code>
    Process p=null;
    int ch=0;
    try
    System.out.println("Before executing command");
    String unlock_command="sh changeuser.sh";
    p = Runtime.getRuntime().exec(new String[] {"/bin/sh","-c","su tony"});
    InputStreamReader myIStreamReader = new InputStreamReader(p.getInputStream());
    while ((ch = myIStreamReader.read()) != -1)
    System.out.print((char)ch);
    p.waitFor();
    int p_exitvalue = p.exitValue();
    System.out.println("After executing the command and the exit value = "+p_exitvalue);
    p.destroy();
    catch (IOException anIOException)
    System.out.println(anIOException);
    catch(Exception e)
    e.printStackTrace();
    </code>
    Thanks
    HowRYou

    Is it possible that this is a re-post of this thread?
    http://forum.java.sun.com/thread.jspa?threadID=636637
    :^)Might be! What gives you that impression?

  • Runtime.exec() and batch files

    I am having a problem on Windows 2000 while trying to execute a batch file with the Runtime.exec() method. Basically, the exit value returned from the call to Runtime.exec(), returned specifically by the waitFor() method in the Process class, is always zero, even if the batch file fails miserably. After looking into batch files further, it seems to me that the only way to get the exit value of the commands run in the batch file back to the Runtime.exec() call is to put "EXIT %ERRORLEVEL%" in the batch file. What this actually does is exit the command(cmd) shell that the batch file was running in with the exit code of the last command run. This is all great when calling the batch file with a Runtime.exec() call, but when you run it in a cmd window, the window closes when the batch file completes, because the call to EXIT exits the entire shell. I guess i'm just wondering, am i correct in assuming the exit value returned to the java process is going to be the exit value of the shell in which the batch file is running? I need to have the exit value actually indicate whether the batch file ran successfully or not, and if i have to put in the EXIT %ERRORLEVE% (which exits the cmd shell with the exit value of the last command run), then i'll do that, but if someone knows a better way of doing this, i am all ears. Thanks in advance

    To run any command from java code, the method is
    Runtime.getRuntime().exec( myCommandString )
    Where, myCommandString is something like "/full/pathname/command".
    If the pathname contains spaces (specifically in Windows), e.g. "c:\program files\windows\notepad", then enclose it in quotes within the quoted string. Or pre-tokenize them into elements of an array and call exec(String[] cmd) instead of exec(String cmd).
    From JDK1.3 there are two new overloaded Runtime.exec() methods. These allow you to specify starting directory for the child process.
    Note, there is a gotcha associated with reading output from commands. When the runtime exec's the process, it passes to it 3 streams, for stdin, stdout, and stderr; the out and err are buffered but the buffer size isn't very big. When your process runs, it reads (if needed) from in, and writes to out and err.
    If it doesn't write more than the buffer-size, it can run to completion.
    But if it tries to write more data to one or the other stream than the buffer can hold, the write blocks, and your process hangs, waiting for you to empty the buffer so it can write some more.
    So after the exec call, get the streams, and read from them in a loop until they both hit end-of-stream (don't block on either one, just read whatever is available from each, each loop iteration).
    Then when the streams have ended, call the process.waitFor() method to let it finish dying.
    Now, here is a code snippet how you achieve this.
    String strCommand = "cmd.exe /c " + strCommand;
    // For Solaris / unix it will be
    // String strCommand = "/usr/cobra/sol/runInstaller.sh";
    boolean bWait = true;
    //execute the command
    try
         Runtime r = Runtime.getRuntime();
         Process pr = r.exec(strCommand);
         Process pr = r.exec(callAndArgs);
         BufferedInputStream bis =new BufferedInputStream(pr.getInputStream ());
         int c=0;
         /** Outlet for IO for the process **/
         while (c!=-1)
              c=bis.read();
         /**Now wait for the process to get finished **/
         if(bWait == true)
              pr.waitFor();
              pr.destroy();
    catch(Exception e)
         System.out.println("Could not execute process " + strCommand);
         return(false);

  • Problem with DMGs and error: "No Mountable File Systems"

    Problem with DMGs and error: "No Mountable File Systems"
    The files are not corrupt. The problem is occurring with all DMGs that are apparently formatted in MS-DOS FAT16. No the file will not mount with Disk utility or any other disk mounter programs I have found.
    This is now the second time this occurred and now effects my MBP and my iMac. First time i spent days with Apple support and the only solution was ultimately back up the data, reformat the HD, start over from scratch and reload everything. That lasted about a month before the problem resurfaced and is now an issue on both iMac and MBP.
    I tried to identify all the programs I installed immediately before the error, as I am convinced it is the result of a software conflict.
    Recent programs includes:
    1) upgrading from Parallels 5.5 to 6.0 on both machines.
    2) using an HP secure II usb drive and setting up a secure disk.
    3) installing new itunes 10
    4) new update to Flip For Mac.
    The files affected are downloaded dmgs, including personal brain and google earth, both which are formatted in FAT16.
    Any help or thoughts? Apple has now spent hours trying and they say i now have to reformat and wipe and start over. That is unacceptable and based on pasted experience the problem is likely to repeat itself. having to wipe and rebuild a HD ever month is not an solution. i need to fid the root problem.
    In the meantime, anyone got a real solution on how to extract the data for a DMG using a different method?
    Message was edited by: remaia

    Where you able to find the solution, i am having the same problem, all was fine till i install some programs only same one i saw did we both did was flip4mac i uninstalled it but the problem is still there, i also restored and erased the hardrive but im not up to doing that all over again. If you found anything out let me know i would greatly appreciate it

  • Problem with the EFI system partition's file system.

    I installed latest yosemite 10.10.2 update - did a verify disk on “WDC WD1001FALS-403AA0 Media” (internal HD on my iMac 21.5-inch, Mid 2011) and got
    Problems were found with the partition map which might prevent booting
    Error: The partition map needs to be repaired because there’s a problem with the EFI system partition’s file system.
    However a verify disk on the volume partition gets a clean bill of health!
    I haven't done a 'repair disk' yet. Thought I'd check if anybody else has same message first.
    Cheers

    I had issues where my MacPro 8-core would not boot after the 10.7.4 upgrade, but my MacBook Air 13" 2011 upgrade worked just fine.
    I had to restore my MacPro HD from my TimeMachine back up. Apparently, the Softraid raid drivers that I use on my MacPro are not compatible yet with 10.7.4. See here for more info:
    http://macperformanceguide.com/blog/2012/20120511_1-MacOSX-SoftRAID.html
    I contacted Softraid and they are already aware of the issues and are working with Apple for a fix.
    Cheers.
    Bud

  • MacBookPro SSD Error- ALERT: The partition map needs to be repaired because there's a problem with the EFI system partition's file system.

    MacBook Pro OS x Mavericks. I have Sandisk 256GB SSD and I am getting a below error message.
    ALERT: The partition map needs to be repaired because there's a problem with the EFI system partition's file system.
    Does anyone know how to resolve this error and fix it ? unfortunately I don't have a Time Machine backup. Thanks!

    Have you tried to run the verify/repair permissions and verify/repair disk through the recovery disk? If that didn't work then I would reinstall the OS after backing up. If that still doesn't work I would take it in.

  • Runtime.exec() paramater "String[] envp"

    Hi,
    envp - array of strings, each element of which has environment variable settings in the format name=value, or null if the subprocess should inherit the environment of the current process.
    That's a formal definition of Runtime.exec()'s function argument
    but what exactly it is responsible for?
    Could you give me any usage examples?
    Thanks!

    It's responsible for setting the environment variable.
    String[] envvars = { "temp=C:\TEMP" };

  • Unix command args in Runtime.exec()

    Hi,
    I am doing the following in a method:
    public void shellCommand(String command) {
    Process p = Runtime.getRuntime().exec("ksh -c " + command);
    ....blaa blaa
    }This works fine, but for some reason it only executes the command String up to the first space. So if I pass ls -la to the method it only sees the ls and ignores the rest of the line.
    Has anyone encountered this, or does anyone know how to get round it?
    Thanks

    You could try the exec() variant that takes an array of strings as args.

  • Problem with Method environment_get_variable (Windows GUI)

    Hello,
    I want to use the Method "cl_gui_frontend_services=>environment_get_variable".
    I try this coding with same keywords ('%TMP%', 'TMP', ...), but the result is ever sy-subrc = 0 und s_path is initial.
    DATA s_path TYPE string.
          CALL METHOD cl_gui_frontend_services=>environment_get_variable
            EXPORTING
              variable             = 'USERPROFILE'
            CHANGING
              value                = s_path
            EXCEPTIONS
              cntl_error           = 1
              error_no_gui         = 2
              not_supported_by_gui = 3
              OTHERS               = 4.
          IF sy-subrc <> 0.
            MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
                       WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
          ENDIF.
    Please, can every body tell what is wrong.
    Thanks

    hi,
    seems to be a problem with java environment...
    see link and note
    [https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes/sdn_oss_bc_fes/~form/handler%7b5f4150503d3030323030363832353030303030303031393732265f4556454e543d444953504c4159265f4e4e554d3d31303237303133%7d]
    take a look at the env-variable:
    QTJAVA=d:Javajre1.5.0_11libextQTJava.zip
    and try to change it to older relase (1.4!)
    Bye

  • Not able to open windows application With Java Runtime .exec class

    Hi,
    We have created a folder with mkdir() function. The folder has some
    text and doc files and i want to open them using java runtime API.
    I am unable to open the files using the syntax
    try {
    Process p=Runtime.getRuntime().exec("cmd /c \ "" + file.getPath());
    p.exitValue();
    catch(Exception e)
    e.printStackTrace();
    This code works perfectly for folders created directly in Win XP without using
    mkdir.
    Also the return values of of class Process is 1 which we understood as illegal thread state. But I still havent got a clue how to fix it.
    Appreciate quick feedback :) Thanks ;)

    First off you're missing a quote (add '+ "\"" after file.getPath()). But the larger problem is that this will attempt to execute these files and they aren't directly executable (you said they're text and document files). Do you really want to execute them?
    If you just want to read them then something like
    BufferedReader ir = new BufferedReader(new FileReader(file))
    would be more appropriate.

  • Problem of using Runtime.exec() to run .bat

    hi,
    i try to rum a .bat in the following way:
    Runtime runtime = Runtime.getRuntime();
    Process proc=runtime.exec("cmd.exe /c c:/test.bat");
    int exitVal=proc.waitFor();
    System.out.println("exitVal: "+exitVal);
    but it doesn' t work...
    ,and i get a exit value '1'
    what dose it mean?

    hi,
    i try to rum a .bat in the following way:
    Runtime runtime = Runtime.getRuntime();
    Process proc=runtime.exec("cmd.exe /c c:/test.bat");if it is already a .bat file, why do you invoke it with cmd.exe?? try running it directly as
    Process proc=runtime.exec("c:/test.bat");

  • Any problems with labview runtime v 7.1 on one host interacting with lvrte 6.1 on another host?

    Using OPC, UDP ant TCP on the host running lv 7.1 runtime, communicating with a second host running lvrte 6.1. Both hosts communicating with cpfp 2020 and using similar IAK files. Need to know if there are any known problems with this scenario. I cannot convert st this time, the legacy 6.1 side.

    Hello,
    Thank you for contcting National Instruments.
    I am not sure I understand your question. The LabVIEW Run Time Engine (LV RTE)is used when you will be running an executable on a target. If you want to run executables on your cFP-2020 that were built in LV 6.1 and 7.1, you will need to make sure that LV RTE 6.1 and 7.1 are installed on the cFP 2020.
    If you wish to run VIs (not executables) targeted to your cFP-2020, you can use LabVIEW Real-Time 6.1 or 7.1, but not both.
    Let me know if you have further questions.
    Sean C.
    Applications Engineer
    National Instruments

  • Remote Debug problem with CVI Runtime Versions.

    Development Platform - CVI Version 8.5.1
    Target has DAQmx 9.4 installed on it along with CVI Runtime Engine ver: 9.1.0.428
    Developmenrt Platform was recently upgraded to DAQmx 9.4
    Re-installed CVI RTE (ver 9.1.0.428) on Development Platform - even though it was already installed.
    I keep on getting this error message on the Target system "The LabWindows/CVI Run-Time Engine on the target is more recent than your Lab Windows/CVI environment.  You have to upgrade the Lab/Windows environment if you want to debug your application."
    Both systems (Development Platform & Target) have the same versions of CVI RTE and DAQmx.  I have done a complete re-compile of the application .exe that I am trying to excute on the Target.  I have re-installed CVI RTE on the Development Platform.
    What is wrong here? 
    Solved!
    Go to Solution.

    LabWindows/CVI Environment == Development platform.
    I.e.: you must either downgrade the runtime engine on your target to match the existing 8.5.1 of the debugging machine or upgrade CVI installation on the development machine to match the 9.1 on the target (if I'm not wrong 9.1 means CVI 2009 SP1). The two machines must have the same version or the debugging machine must be more recent than the target one.
    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?

  • Problems with I/O object to a File

    First of all, hi to everybody, sorry for my English.
    I have a problem with my Exam Project. I need to write and read object (Utente) from a file. Following the Class then a Description of the Error/problem
    questo � il loader
    import java.io.*;
    public class Load {
    public Load(){}
    public void Caricalista(ListKey Lista) throws Exception{
    Utente loaded,x;
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream ("elenco.sav"));
    while((loaded = (Utente)ois.readObject())!=null){
    loaded = (Utente)ois.readObject();
    System.out.println(loaded.nome);
    Lista.insert(loaded);
    x=Lista.head();
    System.out.println(x.nome);}
    ois.close();
    Questo il Saver
    import java.io.*;
    public class Salva {
    public Salva(){}
    public void salva (Utente piero) throws IOException{
    Load loader=new Load();
    ListKey Lista=new ListKey();
    try{ loader.Caricalista(Lista);
    }catch (Exception e){System.out.println ("Errore in Salva.java");}
    FileOutputStream fos = new FileOutputStream ("elenco.sav");
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    Lista.insert(piero);
    Utente test=new Utente();
    int i;
    for(i=0;i<Lista.lenght();i++){
    Lista.scorri(test);
    oos.writeObject(test);
    oos.close();
    public class ListKey extends ListNode {
    public ListKey() {super();}
    public ListKey (Utente o){super(o);}
    public ListKey(Utente o, List l){super (o,l);}
    public Utente find (String user){if (isEmpty())return null;
    if (user.equals(head().nome)) return head();
    return ((ListKey)tail()).find(user);
    public Utente scorri(Utente prova){if (isEmpty()) return null;
    else {prova=head();
    return ((ListKey)tail()).scorri(prova);
    e il main:
    public class mainvia {
    * @param args
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Utente prova=new Utente();
    prova.nome="Tettone";
    prova.psw="300786";
    prova.LibriPrestito="SI";
    prova.TitlePrestito1="IL Giovane Holden";
    ListKey Lista=new ListKey();
    Salva save=new Salva();
    try {save.salva(prova);}catch(Exception e){}
    Load loader=new Load();
    try{loader.Caricalista(Lista);
    }catch(Exception e){}
    Utente x=new Utente();
    System.out.println(x.nome);
    The problem is that, if I use only the Load for open the file,it works great and find the first User, instead if in the Salva I run try{ loader.Caricalista(Lista);
    }catch (Exception e){System.out.println ("Errore in Salva.java");}
    it always goes in Error and print "Errore in Salva.java" like if it can not open the file.
    How Can I Resolve?
    The base idea is the:
    from the mainvia I pass the ListKey Lista to save, then i load all the object from the file to the Lista, then i add to the List the new Object then i write all the object in the List to the file.

    Let's start by printing some useful information about the error, instead of just the fact that an error occurred:}catch (Exception e){e.printStackTrace();}Tell us what that produces.

Maybe you are looking for