Question

when I try to command in command line it executes fine

$: /application/jre/bin/java -classpath /application/common/lib/apps.jar: ./updater.jar com.application.updatermain mobile

This executes perfectly fine and returns me the results whereas when I try putting this in a file called run.sh

If I create a run.sh as

/application/jre/bin/java -classpath /application/common/lib/apps.jar: ./updater.jar com.application.updatermain $@

and try to run it

./run.sh mobile

it acts weird

My java code:

if (args.length == 1) {
    if (args[0].equalsIgnoreCase("mobile") ) {
        updateDB = true;
    } else {
        System.out.println(" 1 :Usage: ./run.sh [mobile] "+ args[0]);
        return;
    }
}

It gives me the output

1 :Usage: ./run.sh [mobile] mobile

Am I missing anything here.

Thanks a lot

Was it helpful?

Solution

it seems that some space add to argument. you must trim the arg[0] :

  if (args.length == 1) {
     if (args[0].trim().equalsIgnoreCase("mobile") ) {
        updateDB = true;
     }
  else {
        System.out.println(" 1 :Usage: ./run.sh [mobile] "+ args[0]);
        return;
     }
  }

OTHER TIPS

Remove the space before "./updater.jar"; the script "run.sh" should contain:

/application/jre/bin/java -classpath /application/common/lib/apps.jar:./updater.jar com.application.updatermain $@
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top