我使用Popen
中的subprocess
启动命令行工具,该工具为我启动Java Scheduler:
from subprocess import Popen, PIPE, STDOUT
import sys
cmd = "java -Xmx600m -cp target/classes:target/dependency/* com.scheduler.app.main config.properties"
scheduler = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE,
stderr=PIPE, close_fds=True)
if scheduler.pid is not None:
print("Scheduler started with PID: %s" % scheduler.pid)
logfile = open('logfile', 'w')
for line in scheduler.stdout:
sys.stdout.write(line)
logfile.write(line)
scheduler.wait()
我得到的唯一输出是:
Scheduler started with PID: 9169
类似的命令以类似的方式启动。当我这样做时:ps aux | grep java
我看到这些进程已经开始了:
psouzamora 9169 0.0 0.0 0 0 s001 Z+ 9:26AM 0:00.00 (java)
psouzamora 9170 0.0 0.0 0 0 s001 Z+ 9:26AM 0:00.00 (java)
psouzamora 9171 0.0 0.0 0 0 s001 Z+ 9:26AM 0:00.00 (java)
psouzamora 9421 0.0 0.0 2445076 804 s017 S+ 9:29AM 0:00.00 grep java
psouzamora 9168 0.0 0.0 0 0 s001 Z+ 9:26AM 0:00.00 (java)
但是,我没有看到任何输出或生成的日志文件。程序正确结束,没有留下僵尸进程。但是,我没有看到任何输出,也没有生成日志文件。
当我从终端执行相同的命令时,我得到:
2015-11-03 09:34:36.269 ${sys:ipaddr} 9965 [main] DEBUG c.c.u.ConfigHandler - property file = staging.properties
2015-11-03 09:34:36.337 ${sys:ipaddr} 9965 [main] INFO o.q.i.StdSchedulerFactory - Using default implementation for ThreadExecutor
2015-11-03 09:34:36.343 ${sys:ipaddr} 9965 [main] INFO o.q.s.SimpleThreadPool - Job execution threads will use class loader of thread: main
2015-11-03 09:34:36.363 ${sys:ipaddr} 9965 [main] INFO o.q.c.SchedulerSignalerImpl - Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
2015-11-03 09:34:36.365 ${sys:ipaddr} 9965 [main] INFO o.q.c.QuartzScheduler - Quartz Scheduler v.2.2.1 created.
2015-11-03 09:34:36.366 ${sys:ipaddr} 9965 [main] INFO o.q.s.RAMJobStore - RAMJobStore initialized.
2015-11-03 09:34:36.367 ${sys:ipaddr} 9965 [main] INFO o.q.c.QuartzScheduler - Scheduler meta-data: Quartz Scheduler (v2.2.1) 'DefaultQuartzScheduler' with instanceId 'NON_CLUSTERED'
Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
NOT STARTED.
Currently in standby mode.
Number of jobs executed: 0
Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.
查看我看到的logs
目录app-2015-11-03.09-34-36.log
应该在那里。我想知道发生了什么。正在执行的命令是正确的。正在启动的java
进程应该继续运行,直到它被首先启动该进程的框架杀死。有人能告诉我一些事情吗?
我已经添加了一段代码来更新我的问题,以便阅读管道。没有输出任何内容,logfile
为空。