简体   繁体   English

如何在Linux中从Java运行sh文件作为后台进程

[英]How to Run sh file from java in linux as background process

I need to run Sh file from java class.In that java main class is from main class it calls another sh file it takes data from db writes to csv file.It should run continuously.in back ground how to make this run.I made thread as setDaemon.But I am not sure that is it running Back end or not?? 我需要从Java类运行Sh文件。在该Java主类来自主类的情况下,它调用另一个sh文件,它将从db写入csv文件的数据中获取。它应该连续运行。在后台如何进行此运行。线程作为setDaemon。但是我不确定它是否在运行后端? When i am running manually that sh file is creating but when i am running backend i did't get any log file or logs. 当我手动运行时,正在创建该sh文件,但是当我运行后端时,我没有任何日志文件或日志。

Good article http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html Its for the old way but gives good insight. 好的文章http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html它是旧方法,但提供了很好的见识。

Article I haven't read of converting to the new way: 我尚未读过转换为新方法的文章:

From Runtime.exec() to ProcessBuilder 从Runtime.exec()到ProcessBuilder

The "&" works in this case like "|" 在这种情况下,“&”的作用类似于“ |” etc.: 等等。:

Runtime.getRuntime().exec("./test.sh &"); Runtime.getRuntime()。exec(“ ./ test.sh&”);

(I made a test on Debian with and endless loop in a shell script and the java got back the control after starting the script) (我在shell脚本中使用无穷循环对Debian进行了测试,并且java在启动脚本后重新获得了控件)

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

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