Runtime.getRunTime().exec not behaving like C language “system()” command

前端 未结 5 419
忘了有多久
忘了有多久 2021-01-13 17:14

In \"C\", I can run a long blocking process in the background (AND HAVE IT CONTINUE TO RUN) after the starting process has exited.

void main(void)
{
      sy         


        
5条回答
  •  旧巷少年郎
    2021-01-13 17:41

    Your problem is probably due to the trailing &. Try removing it.

    getRuntime().exec() is more similar to fork() and exec() than system().

    system() passes the command to the shell, and it's Bash that understands that the trailing ampersand means to run the process in the background.

    getRuntime().exec() parses the command using a StringTokenizer to parse the command, and doesn't do anything with the trailing ampersand. That's simply passed as the first argument to your some_long_blocking_process, which may exit out immediately on the unknown error.

提交回复
热议问题