geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jack Cai (JIRA)" <j...@apache.org>
Subject [jira] Commented: (GERONIMO-4525) No effective exit code for all Windows commands
Date Tue, 10 Feb 2009 02:32:59 GMT

    [ https://issues.apache.org/jira/browse/GERONIMO-4525?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12672124#action_12672124
] 

Jack Cai commented on GERONIMO-4525:
------------------------------------

Why reset errorlevel at line 309 in geronimo.bat - 
because issuing "geronimo.bat run" will call "start java.exe ...", which will not reset errorlevel.

Why call "cmd /c exit /b %errorlevel%" at the end of each batch script -
to set the exit code of the SCRIPT. For example, the below Java code calls the gsh.bat and
then check its exit code. Without "cmd /c exit /b %errorlevel%", the gsh.bat will always exit
with code 0 (I already explained the reason in the previous comment), and there is NO way
to read the errorlevel value because the process executing the script already ends.

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class ProcessTest {
    static class StreamGobbler extends Thread
    {
        InputStream is;
        String type;
        
        StreamGobbler(InputStream is, String type)
        {
            this.is = is;
            this.type = type;
        }
        
        public void run()
        {
            try
            {
                InputStreamReader isr = new InputStreamReader(is);
                BufferedReader br = new BufferedReader(isr);
                String line=null;
                while ( (line = br.readLine()) != null)
                    System.out.println(type + ">" + line);    
                } catch (IOException e) {
                    e.printStackTrace();  
                  }
        }
    }

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception {
        String[] cmds = new String[] {
                "D:\\Dev\\wasce-server-2.1.1.1\\bin\\gsh.bat",
                "-c",
                "geronimo/wait-for-server -u system -w manager -t 10" };
        Process ps = Runtime.getRuntime().exec(cmds, null,
                new File("D:\\Dev\\wasce-server-2.1.1.1\\bin"));

        StreamGobbler errorGobbler = new 
            StreamGobbler(ps.getErrorStream(), "ERROR");            
        
        StreamGobbler outputGobbler = new 
            StreamGobbler(ps.getInputStream(), "OUTPUT");
            
        errorGobbler.start();
        outputGobbler.start();

        // Print the exit code
        int exitVal = ps.waitFor();
        System.out.println("ExitValue: " + exitVal);
    }

}

Hope this helps. Thanks again Jarek!


> No effective exit code for all Windows commands
> -----------------------------------------------
>
>                 Key: GERONIMO-4525
>                 URL: https://issues.apache.org/jira/browse/GERONIMO-4525
>             Project: Geronimo
>          Issue Type: Bug
>      Security Level: public(Regular issues) 
>          Components: commands
>    Affects Versions: 2.1.3
>         Environment: MS Windows
>            Reporter: Jack Cai
>            Assignee: Jarek Gawor
>             Fix For: 2.1.4, 2.2
>
>         Attachments: Geronimo-4525_Jack.patch
>
>
> There are multiple problems in the current Windows batch commands (including geronimo.bat,
startup.bat, etc.)
>  - It's not recommended to define an environment variable with the name ERRORLEVEL. See
[1].
>  - Set a value to ERRORLEVEL has no effect to the exit code of the batch command (so
the documented exit code "0" and "1" are not actually there).
>  - The value of the ERRORLEVEL variable will also get unset when the "@endlocal" command
is called.
> [1] http://blogs.msdn.com/oldnewthing/archive/2008/09/26/8965755.aspx

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message