Process.exec(...) different results within IntelliJ
Answered
Community 2018.3 on a Mac (Mojave 10.14.3), Scala plugin, based on Java 1.8.0_101
Running the 'tmutil' command (Time Machine utility) internally using the Java Process.getRuntime().exec(....) produces different results:
Wrapped execution in a shell, so exactly the same 'tmutil ... params ...' is invoked each time.
Results:
- Running the shell directly from a terminal produces the expected output
- Compiling the whole project into a Jar, and executing: java -jar MyJar.jar produces the expected results
- Running from within Intellij produces different results - it appears to be truncated.
Suspected authorization differences, so put a 'whoami' in the shell and it produces the same user each time. Modified the shell to run it under 'sudo' and same problem. Checked all environment variables and do not see anything which could explain the difference.
Any thoughts?
Please sign in to leave a comment.
IntelliJ IDEA output window in the Run configuration is not a real terminal. Terminal specific features will not work there.
Thanks for the response. Do not believe that this fails because of anything about the Terminal itself, but it may be some type of authorization issue.
This is the actual shell script:
#!/bin/bash
echo "Inside the SHELL - starting"
echo "WhoAmI -- " `whoami`
echo ""
echo ""
tmutil compare -c "/Volumes/Time Machine Backups/Backups.backupdb/thecrowleys\pammac/2019-01-30-151144" "/Volumes/Time Machine Backups/Backups.backupdb/thecrowleys\pammac/2019-01-30-102058"
echo "Inside the SHELL - finished"
In all modes of execution the "echo" output is returned normally. Running the shell directly, or running from the Jar, also gets the expected output from the 'tmutil' statement. But running within Intellij, the 'tmutil' output is exactly what would be returned if one (or both?) of the /Volumes/... paths did not exist or was not readable - hence the speculation that the authorization is different.
On the other hand, the 'whoami' within the shell does show the same user, and the application actually verifies both paths (java.io.File exists(), isDirectory(), canExecute()) before attempting to execute the shell??? (Using the shell is actually a hack to try to isolate this problem. Normally the application reads the paths from the command line, verifies, and then constructs the tmutil command internally.)
Does it work if you run the jar from IntelliJ IDEA Terminal tool window?
Almost certainly some authorization issue. Working on a different section of the app, using java.nio.... stuff to list the files in a directory.
Running within IntelliJ get this:
java.nio.file.FileSystemException: /Volumes/Time Machine Backups/Backups.backupdb/thecrowleys\pammac: Operation not permitted
but putting the project into a Jar artifact and running from the command line it works (just have debug code to list the files):
Serge - our posts crossed in the ether ...
Good suggestion - if I open up a terminal window within IntelliJ it fails with the same exception shown above - ... Operation not permitted.
IntelliJ must be setting up different authorizations.
BTW: running 'whoami' within the IntelliJ terminal window shows my regular login ID
Does it help if you start IntelliJ IDEA from the Terminal using /Applications/IntelliJ\ IDEA.app/Contents/MacOS/idea?
That WORKED!
Thanks so much - now I can at least work & debug in the IDE. Constantly building a Jar, and debugging by print statements was a hassle!
But it does raise the question - what's different???
Maybe you should give IntelliJ IDEA Full Disk Access permissions: http://osxdaily.com/2018/10/09/fix-operation-not-permitted-terminal-error-macos/.
That was it - gave it Full Disk Access & now it works when launched the normal way.
By the way - I've been very close to just disabling this SIP monster, and think that this one has just pushed me over the edge.
Thanks for the help - would have taken me days to figure that out!