• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

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...
0
menakaindrani
Asked:
menakaindrani
  • 4
  • 3
  • 2
  • +1
2 Solutions
 
CEHJCommented:
>>/bin/sh.exe

Would mean that bin was in root C: Is that the case?
0
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now