execute shell script from java

Hi am getting the following error.

public static void RunExe()
    {
          String st = "";
          st = "/bin/sh.exe C:/convert/runshell.sh";                                    
       try
       {
          Runtime.getRuntime().exec ( st ) ;//error here
       }
       catch(Exception ex)
       {
          ex.printStackTrace();
       }
    }

java.io.IOException: CreateProcess: /bin/sh.exe runshell.sh error=2
        at java.lang.Win32Process.create(Native Method)
        at java.lang.Win32Process.<init>(Unknown Source)
        at java.lang.Runtime.execInternal(Native Method)
        at java.lang.Runtime.exec(Unknown Source)
        at java.lang.Runtime.exec(Unknown Source)
        at java.lang.Runtime.exec(Unknown Source)
        at java.lang.Runtime.exec(Unknown Source)
        at cal.Run.RunExe(Run.java:16)
        at cal.Run.main(Run.java:43)

what is the problem...
menakaindraniAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
>>/bin/sh.exe

Would mean that bin was in root C: Is that the case?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
(You need the right path to sh.exe)
0
sciuriwareCommented:
If you are on linux/unix, then

 String st = "/bin/sh.exe /convert/runshell.sh";

will work, provided that the script is in /convert      ...............
<*>
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

sciuriwareCommented:
If you are on MSWindows, the given source will only work
if /bin/sh is on your current disk.
If not, change it to:

     String st = "X:/bin/sh.exe Y:/convert/runshell.sh";

Repplace X: and Y: by the correct drive letters.
<*>
0
MogalManicCommented:
sh.exe should be in your path so you could try:
String st="sh.exe /convert/runshell.sh";
0
sciuriwareCommented:
Again: only when /convert is on your current disk!
Test with FULL pathnames!
<*>
0
CEHJCommented:
>>If you are on linux/unix, then

Unlikely with a .exe extension ;-)

>>sh.exe should be in your path

Why so?
0
MogalManicCommented:
Try this to verify everything:
public static void RunExe()
    {
         File sh=new File("/bin/sh.exe");
         File script=new File("c:/convert/runshell.sh")
        if (sh.exists()==false) {
            throw new FileNotFoundException("Command shell (sh.exe)");
        if (script.exists()==false) {
            throw new FileNotFoundException("Shell script(runshell.sh)");

       String st = sh..getAbsolutePath()+" "+script..getAbsolutePath();
       try
       {
          Runtime.getRuntime().exec ( st ) ;//error here
       }
       catch(Exception ex)
       {
          ex.printStackTrace();
       }
    }
0
CEHJCommented:
getAbsolutePath is not necessary - both paths are already absolute
0
mudriCommented:
"/" means root of the drive where your java app is executed. Try copying java class to the drive where sh.exe is, and things should work fine. Otherwise you'll have to specify full path like "C:/.."
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.