Topic: service ntpd status > /usr/a.log

  Print this page

1.service ntpd status > /usr/a.log Copy to clipboard
Posted by: skwujinhua
Posted on: 2008-12-01 14:56

import java.io.*;
public shell
{
public static void main(String [] args ) throws Exception
{
{
{
String status = null;
Process process = Runtime.getRuntime().exec("/bin/sh service ntpd status > /usr/a.log");
process.waitFor();
}
}
}
}

為什么這樣不能把service ntpd status 服務狀態寫到a.log文件里面?
而直接在shell 輸入 service ntpd status > /usr/a.log
可以正常把狀態寫到a.log里面。哪個大哥提示下? 我讓這程序搞暈了。

2.Re:service ntpd status > /usr/a.log [Re: skwujinhua] Copy to clipboard
Posted by: skwujinhua
Posted on: 2008-12-01 16:08

自己已經解決﹐

因為service ntpd status > /usr/a.log 是文本形命令。
所在把該命令寫在shell文件中﹐也就是linux批處理。

再exec(/bin/sh 文件名);

就可以在a.log中看到結果了。哈哈。。。。。。

但是﹐為什么在排程中執行該程序﹐a.log中確沒有結果。為什么啊?

3.Re:service ntpd status > /usr/a.log [Re: skwujinhua] Copy to clipboard
Posted by: JiafanZhou
Posted on: 2008-12-08 19:43

Link this thread with the following:

http://www.cjsdn.net/post/view?bid=1&id=196586&sty=1&tpg=2&age=0

In the above thread, I have explicitly mentioned that file redirection will *not* work properly in Runtime.getRuntime().exec()....skwujinhua , using a file standard output like ">" will not work within the case here.

Regards,
Jiafan


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923