Add a non-blocking command runner CommandRunnerKt.runCommandNonBlocking() and refactor SystemEnvironmentKt.runCommand() and SystemEnvironmentKt.runCommandWithExitCode() to use it as their base. The main differences are:
Input pipe is closed, if no input is provided.
If the output is not discarded, both output streams are read asynchronously. If the called program times out, the streams are still read until the pipe closes even if they are not already ready. This should not lead to problems as long as Java is able to kill the process. One could try to implement the readers in a less blocking way to at least make them abortable before something is read but this does seem to be a pretty complex problem.
The function is less blocking.
[Breaking] Change parameter nonBlocking of (former) SystemEnvironmentKt.runCommandWithExitCode() to discardOutput. The intent of users of this parameter seems to be to just don't care about the commands output, so this change seems to be safe. Also the implementation of the former behavior is not easy with the added asynchronous contexts for reading the streams.
Increase timeout of kpsewhich path expansion to 10 seconds to allow it to return and added logging of number of paths loaded. (I did not add a check only to increase the timeout on Windows, as is does not seem to block the IDE.)
[Edit 1] Add extension function String.runCommandNonBlocking() and replace usages of String.runCommand() in suspending functions.
I'm not quite sure if it runs in the background. The caller nl.hannahsten.texifyidea.startup.LatexPackageLocationCacheInitializer#execute() seems to run it in the background but I don't know how nl.hannahsten.texifyidea.util.files.LatexPackageLocationCache#getPackageLocation() is called. The former I could not provoke a hanging UI with, even with added delays. The latter I could not provoke a call to without having the cache filled first, so I could not check if it runs in background.
How to test this pull request
Verify the following document does not show error File 'article.cls' not found:
Fix #3653
Summary of additions and changes
CommandRunnerKt.runCommandNonBlocking()
and refactorSystemEnvironmentKt.runCommand()
andSystemEnvironmentKt.runCommandWithExitCode()
to use it as their base. The main differences are:nonBlocking
of (former)SystemEnvironmentKt.runCommandWithExitCode()
todiscardOutput
. The intent of users of this parameter seems to be to just don't care about the commands output, so this change seems to be safe. Also the implementation of the former behavior is not easy with the added asynchronous contexts for reading the streams.kpsewhich
path expansion to 10 seconds to allow it to return and added logging of number of paths loaded. (I did not add a check only to increase the timeout on Windows, as is does not seem to block the IDE.)String.runCommandNonBlocking()
and replace usages ofString.runCommand()
in suspending functions.I'm not quite sure if it runs in the background. The caller
nl.hannahsten.texifyidea.startup.LatexPackageLocationCacheInitializer#execute()
seems to run it in the background but I don't know hownl.hannahsten.texifyidea.util.files.LatexPackageLocationCache#getPackageLocation()
is called. The former I could not provoke a hanging UI with, even with added delays. The latter I could not provoke a call to without having the cache filled first, so I could not check if it runs in background.How to test this pull request
Verify the following document does not show error
File 'article.cls' not found
: