1

My goal is pretty simple: I wan't to execute a shell command (e.g. "pwd") from java code that is on Google Cloud Platform (App Engine in my case). Locally i'm capable of doing so either by a ProcessBuilder or Runtime.getRuntime().exec(...). The thing is that when I'm trying to deploy a Java service on GCP that needs to do that, it fails with the error: java.io.IOException: Cannot run program "pwd": error=2, No such file or directory

I tried working this out with: Runtime.getRuntime().exec(new String[]{"bash", "-l", "-c", "pwd"}, null); Which also works locally, but on GCP it still fails. Anyone?

B.B.
  • 19
  • 4
  • Maybe this might be helpful - https://stackoverflow.com/questions/53638852/cd-command-does-not-work-with-gcloud-compute-ssh-while-other-basic-commands – vatsal gosar May 03 '20 at 22:57
  • If you want to run native programs you'll have to configure a runtime that includes them – that other guy May 04 '20 at 01:12
  • Your first error is that you are using relative paths for the command to be executed. Use complete path names. The second issue is that you are using a shell (bash) to execute commands. This is not necessary and adds complexity. Execute the commands directly with command-line arguments. Third, make sure the command that you are trying to execute is actually a program file with execute permissions on disk and not an alias or built-in shell command. – John Hanley May 04 '20 at 01:12
  • @vatsalgosar thanks but that's not the case. – B.B. May 04 '20 at 10:32
  • @thatotherguy what do you mean? can you give me example? say just for running "pwd" or other simple shell command. – B.B. May 04 '20 at 10:35
  • @ I just want to run "pwd". no relative paths included – B.B. May 04 '20 at 10:36
  • The App Engine Java Runtime doesn't come with shells or utilities, so you have to include `/bin/pwd` plus any libraries it may need. See [Custom Runtime](https://cloud.google.com/appengine/docs/flexible/custom-runtimes) for how to include and run arbitrary executables – that other guy May 04 '20 at 15:54

0 Answers0