Reputation: 652
I'm running below code on windows using java and want to run same code on CENT OS machine using java but not getting any fruitful. Please let me know what changes are required to solve this issue.
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
public class CommandPrompt {
public static void main(String[] argv) throws Exception {
try {
Process child = Runtime.getRuntime().exec(commands);
child = Runtime.getRuntime().exec("cmd /c \"\" aws cp E:\\rock.jpg s3://bucket");
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(child.getOutputStream()));
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1) {
System.out.print((char) c);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
in.close();
}
}
}
Now I want run above code on cent os (unix) but not getting any fruitful.
Upvotes: 0
Views: 67
Reputation: 140525
Here:
child = Runtime.getRuntime().exec("cmd /c \"\" aws cp E:\\rock.jpg s3://bucket");
You are invoking the Windows cmd
shell to invoke the aws binary to copy a local file to s3.
Please note: it is A) a windows specific command, and B) using windows specific file system details.
The short answer: don't expect that to work on any other operating system then. Unless you remove the part to use "cmd".
For a Linux system, you have to make sure some aws tools is in your path and to use a Linux like file path.
But the real solution is to turn to https://aws.amazon.com/sdk-for-java/ and to not call some aws binary using the command line but to use Java interfaces to do these tasks directly in Java code!
Upvotes: 1