Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2003
    Posts
    20

    Unanswered: Passing argument from java to shell script

    Hi

    I am trying to call shell script from java program.I tried it using
    Process p=Runtime.getRuntime().exec("filename.sh");
    Along with the filename,i want to pass parameters to the shell script. How to do this???

    Waiting for ur quick reply.
    Thanks in advance,
    Bye
    Prasanthi

  2. #2
    Join Date
    Dec 2002
    Posts
    104

    Re: Passing argument from java to shell script

    Originally posted by prasanthik83
    Hi

    I am trying to call shell script from java program.I tried it using
    Process p=Runtime.getRuntime().exec("filename.sh");
    Along with the filename,i want to pass parameters to the shell script. How to do this???

    Waiting for ur quick reply.
    Thanks in advance,
    Bye
    Prasanthi
    hi,

    i have no idea about java, but its just a thought.

    did u tried Process p=Runtime.getRuntime().exec("filename.sh param1 param2");


    --pooja

  3. #3
    Join Date
    Dec 2003
    Posts
    20
    Hi pooja !

    Thank u very much for your solution. I tried it and got the solution.

    Bye
    Prasanthi

  4. #4
    Join Date
    Dec 2003
    Posts
    20
    Hi !
    I am trying to send a variable to shell script from java.
    i.e txtstr="xxx"
    Process p=Runtime.getRuntime().exec("filename.sh 'txtstr'");
    But it is taking argument as a txtxstr but not its value.
    How to solve this?????

    Thanks in advance,
    Waiting for ur reply,
    Bye
    Prasanthi

  5. #5
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    Like this?

    Process p=Runtime.getRuntime().exec("filename.sh " txtstr);

  6. #6
    Join Date
    Mar 2004
    Posts
    1

    Re: Passing argument from java to shell script

    make an array of String and pass it to exec() for e.g
    i want to use Net Send command from java:

    String params={"NET","SEND","COMPUTER/USER ID","Your Message"};

    Process p=Runtime.getRuntime().exec(params);


    can you plz send me the code how you have invoked the shell script on my email: maknojia@gem.net.pk

  7. #7
    Join Date
    Sep 2012
    Posts
    1
    This is tried and tested solution for this:

    String param1 = "45";
    Process p1 = rt.getRuntime().exec("<script path >"+" "+param1);

    for eg
    Process p1 = rt.getRuntime().exec("home/ndadwal/LogoChangeParam.sh"+" "+param1);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •