Run sh in java

Asked

Viewed 240 times

0

I am trying to run a file in java with the following command

System.out.println("Linux");
String[] env = {"PATH=/bin:/usr/bin/"};

String cmd = System.getProperty( "user.dir" ) + "/config/atualiza.sh";

  try {
    Process process = Runtime.getRuntime().exec(cmd, env);
  } catch (IOException ex) {
     Logger.getLogger(TestandoSO.class.getName()).log(Level.SEVERE, null, ex);
  }

But nothing happens.

I have already tested running through the terminal sh and runs normally.

My goal is to call another file jar. As I could not by Java I am trying by sh

1 answer

0

Try to check if you are giving a message when executing the command:

try
{
    Process p = Runtime.getRuntime().exec( "COMANDO" );

    InputStream is        = p.getInputStream();
    InputStreamReader isr = new InputStreamReader( is );
    BufferedReader br     = new BufferedReader( isr );

    while ( ( line = br.readLine() ) != null )
    {
        sb.append( line + "\n" );
    }

    System.out.println.( sb.toString() );
}

catch( Exception e )
{
    e.printStackTrace();
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.