4

I'm getting the below error when trying to run a shell script from java in Eclipse.

I just created a text file on my local and wanted to see if it will run.

new ProcessBuilder("C:/Users/myDir/Desktop/ss1.sh").start();

2 Answers 2

12

You cannot run a shell script on Windows directly as it is no executable in the Windows sense (only .exe, .com, .cmd and .bat are executables).

Call bash.exe or sh.exe and use your script as the first parameter.

Sign up to request clarification or add additional context in comments.

3 Comments

what does that look like?
new ProcessBuilder("path-to-bash/bash.exe C:/Users/myDir/Desktop/ss1.sh").start(); or new ProcessBuilder("path-to-bash/bash.exe -c C:/Users/myDir/Desktop/ss1.sh").start();
thanks that got rid of the error,,,but nothing is happening. If I run through cygwin directly the script runs
-1

Following MrTux comment I wrapped the py script that I was calling from groovy in a bat file and, voilà!, it works.

Calling directly the py script from groovy

def proc = "C:\\MyDir\\myScript.py param1 param2 param3".execute()
proc.waitFor()
def result = proc.in.text
def error = proc.err.text

it fails

Wrapping the py script in a bat file def proc = "C:\MyDir\myScriptWrapper.bat param1 param2 param3".execute()

works

Wonder why this behaviour in Windows is not better documented. And many thanks to MrTux

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.