简体   繁体   English

JAR文件未在crontab执行时从Scanner(System.in)读取输入

[英]JAR file not reading input from Scanner(System.in) on crontab execution


I have created some application, which is reading from System.in using the following method: 我创建了一些应用程序,它使用以下方法从System.in读取:

    Scanner input = new Scanner(System.in);

    while (input.hasNextLine()) {

        String line = input.nextLine();

    }

Input data is being passed with linux command: 使用linux命令传递输入数据:

cat -A /home/someuser/somefile.txt | java -classpath "$CLASSPATH" com.test.Main

The crontab entry looks like: 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

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. 一切都在我的机器上工作正常(Ubuntu 9),但在另一台机器Ubuntu 8上安装后,我发现程序启动但似乎没有读任何东西。 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. 当我手动运行命令时,一切正常,当它由crontab运行时,似乎没有读取输入。 Anyone experienced this issues before? 以前有人遇到过这个问题吗

Thanks for any help 谢谢你的帮助
Serhiy. 谢尔盖。

Are you defining the variables in crontab ? 你在crontab中定义变量了吗? That does not seem right. 这似乎不对。

1) Move the command to a shell script and invoke the shell command from cron, eg 1)将命令移动到shell脚本并从cron调用shell命令,例如

*/10 * * * * /home/someuser/some_script.sh >/home/someuser/some_script.cronoutput 2>&1

2) Contents of some_script.sh ; 2)some_script.sh的内容; make sure the execute bit is set 确保执行位已设置

#!/bin/sh
export MAILTO=someuser  
export CLASSPATH="/home/someuser/test.jar:/usr/share/java/jdom.jar:/usr/share/java/mysql-connector-java.jar"  

cat -A /home/someuser/somefile.txt | java -classpath "$CLASSPATH" com.test.Main  >/home/someuser/output.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM