JAR 文件在 crontab 执行时未从 Scanner(System.in) 读取输入
我创建了一些应用程序,它使用以下方法从 System.in 读取:
Scanner input = new Scanner(System.in);
while (input.hasNextLine()) {
String line = input.nextLine();
}
输入数据通过 linux 命令传递:
cat -A /home/someuser/somefile.txt | java -classpath "$CLASSPATH" com.test.Main
crontab 条目如下所示:
MAILTO=someuser
CLASSPATH="/home/someuser/test.jar:/usr/share/java/jdom.jar:/usr/share/java/mysql-connector-java.jar"
0,10,20,30,40,50 * * * * cat -A /home/someuser/somefile.txt | java -classpath "$CLASSPATH" com.test.Main >/home/someuser/output.txt
文件的权限显示以下内容:
-rw-r--r-- 1 someuser serhiy 8385601 2011-02-07 10:57 /home/someuser/somefile.txt
我的机器上一切正常( Ubuntu 9),但是在另一台机器 Ubuntu 8 上安装后,我发现程序启动了,但似乎没有读取任何内容。我已经三次检查了所有配置和所有权限,结果仍然相同。当我手动运行命令时,一切正常,当它由 crontab 运行时,它似乎没有读取输入。以前有人遇到过这个问题吗?
感谢您的帮助
谢尔希。
I have created some application, which is reading from System.in using the following method:
Scanner input = new Scanner(System.in);
while (input.hasNextLine()) {
String line = input.nextLine();
}
Input data is being passed with linux command:
cat -A /home/someuser/somefile.txt | java -classpath "$CLASSPATH" com.test.Main
The crontab entry looks like:
MAILTO=someuser
CLASSPATH="/home/someuser/test.jar:/usr/share/java/jdom.jar:/usr/share/java/mysql-connector-java.jar"
0,10,20,30,40,50 * * * * cat -A /home/someuser/somefile.txt | java -classpath "$CLASSPATH" com.test.Main >/home/someuser/output.txt
The permissions for the files shows the following:
-rw-r--r-- 1 someuser serhiy 8385601 2011-02-07 10:57 /home/someuser/somefile.txt
Everything is working fine on my machine(Ubuntu 9), but after installation on another machine Ubuntu 8, I figured out that program starts but seems not to be reading anything. I have triple checked all configurations and all permissions and the result still the same. When I run command manually everything is working, when it's ran by crontab it seems not reading input. Anyone experienced this issues before?
Thanks for any help
Serhiy.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在 crontab 中定义变量吗?这似乎不对。
1) 将命令移至 shell 脚本并从 cron 调用 shell 命令,例如
2) some_script.sh 的内容;确保设置了执行位
Are you defining the variables in crontab ? That does not seem right.
1) Move the command to a shell script and invoke the shell command from cron, eg
2) Contents of some_script.sh ; make sure the execute bit is set