I am using a shell script to request an api to analyze an image (stored remotely, url given as parameter to the script) and read the output which will be further processed. The script reads from a file containing a key to authenticate myself. When I run the script from terminal it read the file as normal, but when run by a git bash process created by the ProcessBuilder class it cannot interact with directories entirely. For example the ls command returns blank when run on a nonempty readable executable directory.
java snippet:
public static void main(String[] args) throws IOException {
ProcessBuilder pb = new ProcessBuilder("C:/Program Files/Git/usr/bin/bash.exe", "-c", "src/hash_methods/AzureVision/analyze-img.txt");
pb.directory(new File("./")); //i checked the path, trus me
Process process = pb.start();
BufferedReader reader =
new BufferedReader(new InputStreamReader(process.getInputStream()));
StringBuilder builder = new StringBuilder();
String line = null;
while ( (line = reader.readLine()) != null) {
builder.append(line);
builder.append(System.getProperty("line.separator"));
}
String result = builder.toString();
}
analyze-img.txt:
#!/usr/bin/bash
key="$(cat $(pwd)/src/hash_methods/AzureVision/resource_key.txt)"
#again i checked the path
endpoint="redacted"
echo $key #outputs blank
#Code to call a service for image analysis
Permissions might come into play here, the files are all accessible, but the java or bash process might not have them in which case i don't know how to give it to them.