Reputation: 151
I'm trying to run this script shell from java, but it's not working.
I get this error message:
Process exited with an error: 1 (Exit value: 1)
Can someone help?
String pwd = "blabla";
String s_key = "0000";
String path = "C:/Files/scripts";
CommandLine commandLine = CommandLine.parse("C:\\Program Files (x86)\\Git\\bin\\git.exe");
commandLine.addArgument("fileName.sh");
commandLine.addArgument(password);
commandLine.addArgument(s_key);
DefaultExecutor defaultExecutor = new DefaultExecutor();
ByteArrayOutputStream sdtout = new ByteArrayOutputStream();
ByteArrayOutputStream sdterr = new ByteArrayOutputStream();
PumpStreamHandler streamHandler = new PumpStreamHandler(sdtout, sdterr);
defaultExecutor.setStreamHandler(streamHandler);
defaultExecutor.execute(commandLine);
Here is the script
#!/bin/sh
pwd=$1
s_key=$2
....
echo $pwd
it works well with git bash
$ ./fileName.sh blabla 0000
nkfjWmiG7dDnYUmjr6VD0A==
Upvotes: 0
Views: 1255
Reputation: 40739
There are a couple issues with your code:
git-bash.exe
rather than git.exe
Upvotes: 0
Reputation: 8324
There are some points to be aware of.
%windir%\system32\cmd.exe /c ""C:\Program Files\Git\git-bash.exe" --login -i -- D:\temp\test.sh param1"
public static void main(String[] args) throws IOException { String[] command = {"C:\\\\Program Files\\\\Git\\\\git-bash.exe", "D:\\temp\\test.sh", "param1"}; ProcessBuilder processBuilder = new ProcessBuilder(command); processBuilder.redirectErrorStream(true); processBuilder.start(); }
Upvotes: 1