View Javadoc
1   package org.codehaus.mojo.natives.util;
2   
3   import org.codehaus.mojo.natives.NativeBuildException;
4   import org.codehaus.plexus.util.cli.CommandLineException;
5   import org.codehaus.plexus.util.cli.CommandLineUtils;
6   import org.codehaus.plexus.util.cli.Commandline;
7   import org.codehaus.plexus.util.cli.DefaultConsumer;
8   import org.codehaus.plexus.logging.Logger;
9   
10  public class CommandLineUtil
11  {
12      public static void execute( Commandline cl, Logger logger )
13          throws NativeBuildException
14      {
15          int ok;
16  
17          try
18          {
19              DefaultConsumer stdout = new DefaultConsumer();
20  
21              DefaultConsumer stderr = stdout;
22  
23              logger.info( cl.toString() );
24  
25              ok = CommandLineUtils.executeCommandLine( cl, stdout, stderr );
26          }
27          catch ( CommandLineException ecx )
28          {
29              throw new NativeBuildException( "Error executing command line", ecx );
30          }
31  
32          if ( ok != 0 )
33          {
34              throw new NativeBuildException( "Error executing command line. Exit code:" + ok );
35          }
36      }
37  }