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==
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(); }
There are a couple issues with your code:
git-bash.exe
rather than git.exe
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.