暴发户 System.in.read() 使进程崩溃?
upstart System.in.read() crashes the process?
我的java申请只有这个:
System.out.println("waiting for input...");
PrintWriter writer = new PrintWriter("/home/pc/test-java.txt", "UTF-8");
writer.println("The first line");
writer.println("The second line");
writer.close();
System.in.read();
文件创建得很好,然后进程似乎在没有警告的情况下终止。我在文档中找不到任何可以解释此行为的内容。我根本不允许等待输入吗?暴发户怎么会知道我正在尝试读取输入并阻止它呢?为什么要关心?我只是在这里测试新贵脚本。
这是完整的脚本:
start on runlevel [2345]
stop on runlevel [016]
respawn
respawn limit 2 5
script
exec java -jar /home/pc/test-0.0.1-SNAPSHOT.jar
end script
来自 Upstart documentation for the console
stanza 的一些相关片段:
For all versions of Upstart prior to v1.4, the default value for console was console none
. As of Upstart 1.4, the default value is console log
.
6.5.1 console log
Connects standard input to /dev/null.
6.5.2 console none
Connects the job's standard input, standard output and standard error file descriptors to /dev/null.
6.5.3 console output
Connects the job's standard input, standard output and standard error file descriptors to the console device.
因此,在所有版本的 Upstart 中,stdin
默认映射到 /dev/null
。因此,System.in.read()
立即读取文件结尾 (EOF) 和 returns.
要获得您似乎想要的行为,请将 console output
或 console owner
添加到您的 Upstart 工作定义中:
start on runlevel [2345]
stop on runlevel [016]
respawn
respawn limit 2 5
console output
# OR
#console owner
script
exec java -jar /home/pc/test-0.0.1-SNAPSHOT.jar
end script
我的java申请只有这个:
System.out.println("waiting for input...");
PrintWriter writer = new PrintWriter("/home/pc/test-java.txt", "UTF-8");
writer.println("The first line");
writer.println("The second line");
writer.close();
System.in.read();
文件创建得很好,然后进程似乎在没有警告的情况下终止。我在文档中找不到任何可以解释此行为的内容。我根本不允许等待输入吗?暴发户怎么会知道我正在尝试读取输入并阻止它呢?为什么要关心?我只是在这里测试新贵脚本。
这是完整的脚本:
start on runlevel [2345]
stop on runlevel [016]
respawn
respawn limit 2 5
script
exec java -jar /home/pc/test-0.0.1-SNAPSHOT.jar
end script
来自 Upstart documentation for the console
stanza 的一些相关片段:
For all versions of Upstart prior to v1.4, the default value for console was
console none
. As of Upstart 1.4, the default value isconsole log
.6.5.1
console log
Connects standard input to /dev/null.6.5.2
console none
Connects the job's standard input, standard output and standard error file descriptors to /dev/null.6.5.3
console output
Connects the job's standard input, standard output and standard error file descriptors to the console device.
因此,在所有版本的 Upstart 中,stdin
默认映射到 /dev/null
。因此,System.in.read()
立即读取文件结尾 (EOF) 和 returns.
要获得您似乎想要的行为,请将 console output
或 console owner
添加到您的 Upstart 工作定义中:
start on runlevel [2345]
stop on runlevel [016]
respawn
respawn limit 2 5
console output
# OR
#console owner
script
exec java -jar /home/pc/test-0.0.1-SNAPSHOT.jar
end script