Execute a shell line

Hi,
I'm working for a while now over a class that would execute whatever shell command sent. In order to execute a bat in a network folder, I need to use the pushd/popd trick. The problem is that it works when I execute it manually but it doesn't when I execute it over Java.
Here is the Shell line:
pushd \\computer\folder1\folder2 && temp.bat && popdHere is how I call my Shell from Java:
Process process = Runtime.getRuntime().exec(command.toString());Why does it works manually but not using Java? I've double check all the user access and everything is OK.
Anyone ever pass by that problem?
Thanks in advance,

Hi all,
You were right ijp, no need for the pushd/popd workaround. Now, everything seems to work except for the ".exe" called from a ".bat". If I don't add the "/B" to this call START /B myexecutable.exe it doesn't stop reading the buffer even if the executable stopped running.
Do I always have to put the "/B" parameter?
Thanks a lot for the help!
Mickaël Jalbert

Similar Messages

  • Error while executing unix shell script from java program

    Hi All,
    I am trying to execute unix shell script from a java program using Runtime.execute() method by passing script name and additional arguments.
    Code snippet :
    Java Class :
    try{
         String fileName ="test.ksh";
         String argValue ="satish"; // value passed to the script
         String exeParam = "/usr/bin/ksh "+fileName+" "+argValue;
         Process proc = Runtime.getRuntime().exec(exeParam);
         int exitValue = proc.waitFor();
         sop("Exit Value  is : "+exitValue);
    catch(Exception e)
    e.printStackTrace();
    }Test.ksh
      export -- application realated paths..
      nohup  abc.exe 1> test.log 2>&1;
      $1
      exit.By running the above java class , i am getting exit Value: 139 and log file test.log of 0 bytes.
    when i am running the same command (/usr/bin/ksh test.ksh satish) manually, it's calling abc.exe file successfully
    and able generate the logs properly.
    Pls let us know where exactly i am stuck..
    Thanks in advance,
    Regards,
    Satish

    Hi Sabre,
    As per the guidelines provided by the article, i had done below changes..
    InputStream is = null;
    InputStreamReader iStreamReader = null;
    BufferedReader bReader = null;
    String line = null;
    try{
    String fileName ="test.ksh";
    String argValue ="satish"; // value passed to the script
    String exeParam = "/usr/bin/ksh "+fileName+" "+argValue;
    Process proc = Runtime.getRuntime().exec(exeParam);
    is = proc.getErrorStream();
    iStreamReader = new InputStreamReader(is);
    bReader = new BufferedReader(iStreamReader);
    System.out.println("<ERROR>");
    while((line = bReader.readLine()) != null)
    System.out.println("Error is : "+line);
    System.out.println("</ERROR>");
    int exitValue = proc.waitFor();
    sop("Exit Value is : "+exitValue);
    catch(Exception e)
    e.printStackTrace();
    Now , it's showing something like..
    <ERROR>
    </ERROR>

  • Executing a shell script from a java program

    Hi,
    I'm facing a problem while executing a shell script from a jsp page.
    I'm using exec() function.
    It's working fine for single statement scripts.But if the script consists of any database processing and some other processing statements,it's not returning the correct exit status of the process.
    Will u please help me in this.
    If there is any other ways to execute a shell script from a jsp page other than Runtime.exec().If so let me know.
    Thanks in advance.

    I think this shud workMaybe - but it is wrong! Why do you create aReader
    and then read bytes which are turned into a String
    without worrying about whether or not the bytes area
    String and without worrying about the character
    encoding if the bytes do represent characters and
    without worrying about how many bytes wereactually
    read.
    Also, both you and the OP should read, digest and
    follow the advice given in
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-
    traps.htmlI dont care if it is wrong. This code works for me.
    We are here to solve problems not to find which post
    is wrong.It is wrong! You are posting bad advice that is very wrong! It may work for you but it is wrong in general! WRONG WRONG WRONG.
    If you have a solution then post it I did post a solution! The reference I gave will explain to you and the OP exactly how it should be done.
    rather then
    posting rude comments.I was not rude! I was explaining just some of what was wrong!

  • Executing a shell script from a jsp page

    Hi,
    I'm facing a problem while executing a shell script from a jsp page.
    I'm using Runtime.exec() function.
    It's working fine for single statement scripts.But if the script consists of any database processing and some other processing statements,it's not returning the correct exit status of the process.
    Will u please help me in this.
    If there is any other ways to execute a shell script from a jsp page other than Runtime.exec() like RMI etc,.If so let me know.
    Thanks in advance.

    Hello,
    It's hard to help you but what you can do is listening to the outputs of your script, you should read the output stream and error stream and send them to the default console.
    Check this excellent article : http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=4
    Best regards,
    Olivier.

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

  • How to use dbms_pipe to execute a shell program

    Hi ,
    I have a stored procedure....with an if else condition in it
    what i want is
    if condition is true... then
    execute the shell script
    else
    do nothing
    how do i achieve this ? how do i execute a shell script from with in stored proc .. i heard dbms_pipe can be help ful ..could any one throw more light or an example to achieve this?

    learning_man wrote:
    sure i have gone through that option... but the thing is that.....i wnat to run the shell script only if a certain condition inside the stored proc passed some thing like
    if condition = true then
      dbms_scheduler.create_job(
      job_name   => 'TESTSH',
      job_type   => 'EXECUTABLE',
      job_action => '/mydir/myscript.sh',
      start_date => SYSTIMESTAMP,
      enabled    => TRUE,
      comments   => 'testsh');
    else
    dont do anything...
    end if;
    where as scheduler is used to schedule .... the time... i dont want to schedule the time.... i want to run the shell script based on some condition becoming true inside the procAbove code snippet does exactly what you're talking about.
    Max
    http://oracleitalia.wordpress.com

  • 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 shell script from Java ...

    Hi,
    Anyone know how to execute unix shell script from Java?
    Suppose I have several shell scripts written in perl or tcl or bash.
    I just want to catch the output of that script.
    Is there any ready to use module/object for this?
    Please let me know, this is quite urgent for my study assigment.
    Thanks in advance,
    Regards,
    me

    Look up Runtime.exec()

  • How to execute unix shell script in webdynpro?

    hi all,
      We have some iquirement of executing script in unix.If anyone know How to execute unix shell script in webdynpro?
    best regard
    reefish

    Ree,
    1. Find SSH client for windows, then execute SSH with Runtime.exec() on local host with arguments like remote host, auth, command to execute etc.
    2. Get SSH client in Java and execute SSH commands on remote host using pure Java API.
    Don't ask me for links, Google works today, I checked this
    Valery Silaev
    SaM Solutions
    http://www.sam-solutions.net

  • How to execute a shell command?

    What class and method should I use to set an environment variable on a local system? And how do I execute a shell command in Java?
    Thanks!

    I don't know about setting environment variables from java, but I do know how to execute system commands (and from there you could modify environment variables).
    Use Runtime.getRuntime().exec()
    There are quite a few pitfalls with using this though...
    1. It's platform dependent
    2. Doing this creates a Process. If this process has output, you need to read this, otherwise the output buffer will overflow, and that would be bad... Input is not so bad (either supplying it or not ;)
    3. If you use Win for example, and want to do a "dir", there are complications, as there is no dir.exe file, and hence it can't be executed... Do a search for this topic, there's plenty on how to get around it.
    Anyway, there's plenty more info on Runtime.getRuntime().exec(), have a look around.
    Cheers,
    Radish21

  • How to execute a shell script?

    Hi,
    could someone please tell me the correct way to execute a shell script? For example run.sh located in my resources?
    Thanx in advance!

    Odds are good that Apple doesn't want you running shell scripts on an iPhone, but somebody else might have information to the contrary.

  • Aerender error: "Unable to execute script at line 95. Window does not have a constructor"

    A BG Renderer user is getting this error when running aerender version 10.5.1x2:
    "Unable to execute script at line 95. Window does not have a constructor"
    The render proceeds but the process never completes which is preventing the rest of the BG Renderer notifications from triggering.  Any idea what this error means and how to fix it?
    Thanks,
    Lloyd

    I guess we'll have to wait for Adobe to answer what could be causing the transmission to drop on Line 95. Todd's out of the office for a month or two, but maybe someone else can shed some light.

  • Executing a shell command

    Hi,
    I'm new hier and have a short question. How do I execute a shell command from Java code?
    Have a nice day and lot of fun
    Yury

    Search the forum. This is explained well in other threads

  • Execute a code line by line

    Hi, everyone
    according to you, what is the smartest way to execute a code line by line?
    Imagine the following situation : i got the following code:
    System.out.println("1");
    System.out.println("2");
    System.out.println("3");
    I got a GUI with a simple button "Execute next instruction" and a TextField ; each time the button is pressed, the next println is executed, so as the first click let appear a "1" in the textfield, the second click a "2", and the third one a "3"
    Ideas? Suggestions?
    Thanks in advance

    finally i did something like this:
    public class Example1 extends DebuggableCode {
        Memory mem = new Memory();
        Variable i, pi;
        @override
        public String getCCode() {
              return "int i = 10 ; \n int*pi = &i; \n *pi = 12; \n";
        @override
        public void execute() {
             switch (this.currentInstruction) {
                   case 0 : mem.add(i = new Int(10), Memory.STACK); break;
                   case 1 : mem.add((pi = new IntPointer(mem.getAddressOf(i)), Memory.STACK); break;
                   etc.
             this.fireMemoryChanged();
             this.currentInstruction++;
    }this way, the c code is first translated into java instructions with a mini framework to represent memory allocation, usage, etc, and then executed line by line with each new call to execute()
    don't think if it's a really good solution but i think it may work (not yet implemented)
    Edited by: calvino_ind on Jan 21, 2008 3:19 PM

  • Terminal is trying to auto-execute a shell script

    I can no longer use Terminal because every time I try to start it, it automatically runs a shell script I used to have on my desktop and then immediately says "[Process Completed]." I'm not sure how exactly I got it to do this... as far as I know all I did was execute the shell script by associating it with Terminal and double clicking it... but now I can't create a new shell without it automatically attempting to execute it. Please help!
    Thanks,
    Michael

    nevermind... found this http://www.starglider.net/MacOS_X/Terminal-ExecutionString.html
    Apparently I'm not the only one who's made this incredibly aggravating mistake

Maybe you are looking for