3

I'm writing a node.js application deployed through linkedin's glu platform.

The command to launch calls sudo -u <user> node app.js to start the node app as the right user, basically storing this command as a string and calling Groovy's exec() command on it.

The node app makes use of cluster to fork based of the number processors available, but basically it main job is to get some info and then launch a shell script via exec().

Sometimes the shell script will error out which is ok, but the problem is that when running under glu sometimes these shell scripts will become defunct on error, but should i start the node process through the terminal using sudo -u <user> node app.js, the process launches fine and the shell process get cleaned up properly.

What could cause the difference in behavior?

4

1 回答 1

4

就在这里。一个在 shell 中运行,一个直接执行。管道、shell 变量、命令行选项等的处理方式在 shell 中运行和通过底层 Posixexec(3)和 co 运行时都非常不同。(即,exec()在 Java 中使用不会导致您的进程在系统 shell 中运行。)

您需要使用 Java 等价物popen,运行bash和执行您的命令作为参数,或其他类似的东西。

后者的一个例子csh

Process p = Runtime.getRuntime().exec(new String[]{"csh","-c","cat ~/myfile.txt"});

于 2013-01-05T23:17:02.943 回答