如何通过Windows CMD捕获和显示任务的输出 [英] How to capture and display output from a task via Windows CMD

查看:481
本文介绍了如何通过Windows CMD捕获和显示任务的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP脚本,我从命令行(windows)运行,执行各种任务,它提供的唯一输出是通过'print'语句直接输出到屏幕。

I've got a PHP script which I'm running from a command line (windows) that performs a variety of tasks, and the only output it gives is via 'print' statements which output direct to screen.

我想要做的是捕获到一个日志文件。

What I want to do is capture this to a log file as well.

我知道我可以做: p>

I know I can do:

php-cli script.php > log.txt  

但是这种方法的问题是所有输出都写入日志文件,但我不能看到事情是如何运行的(所以我可以停止的过程,如果发生任何惊吓)。

But the problem with this approach is that all the output is written to the log file, but I can't see how things are running in the mean time (so I can stop the process if anything dodgy is happening).

只是为了抢先其他可能问题,我不能改变所有的打印的日志语句,因为有太多的,我不想改变代码中的任何东西,以免我被指责为东西去fubar。另外还有缺乏时间方面。

Just to pre-empt other possible questions, I can't change all the print's to a log statement as there are far too many of them and I'd rather not change anything in the code lest I be blamed for something going fubar. Plus there's the lack of time aspect as well. I also have to run this on a windows machine.

提前感谢:)

编辑:感谢答案家伙,最后我用浏览器方法,因为这是最简单和最快速的设置,虽然我相信有一个实际的答案这个问题在某个地方。

Thanks for the answers guys, in the end I went with the browser method because that was the easiest and quickest to set up, although I am convinced there is an actual answer to this problem somewhere.

推荐答案

我一直在我的网络浏览器中打开日志文件。这允许我很容易刷新它,不会打断任何写入文件的窗口。它不是特别优雅,但它的确工作!

I have always opened the log file up in my web browser. This allows me to refresh it easily and does not interrupt any writing to the file that windows does. It isn't particularly elegant but it does work!

这篇关于如何通过Windows CMD捕获和显示任务的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆