Open qq1100 opened 2 weeks ago
Received upon completion of task execution log,solution?
I'm not I completely understand the question but if you want to listen to the stdout/strerr stream you have to create a controller. There is a completely undocumented ShellLinesController (https://github.com/tekartik/process_run.dart/blob/f2bd2e98690f3a60ec4e91ff6608a8fba0b91265/packages/process_run/test/doc_test.dart#L20-L21) that provides an easy way to listen to streamed lines from either stdout or stdin
我不完全理解这个问题,但如果你想监听 stdout/strerr 流,你必须创建一个控制器。有一个完全没有记录的 ShellLinesController (
) 提供了一种简单的方法来监听来自 stdout 或 stdin 的流式线路
Hello, I just tried controller.stream.listen but there is still no log output. Is it necessary to configure properties when logging through CMD on Windows
I don't which app you are spawning and whether it does have output (many windows app simply don't output anything). Sometimes the option runInShell
is necessary (no idea when and why).
You can try with a simple echo
command first.
我不知道您正在生成哪个应用程序,以及它是否有输出(许多 Windows 应用程序根本不输出任何内容)。有时该选项
runInShell
是必要的(不知道何时以及为什么)。您可以先使用一个简单的命令尝试
echo
。
The cmd command-line tool for Windows can view logs in real-time, but onProcess can only receive logs after the task is completed and cannot obtain logs in real-time
I'm not sure what you are trying to achieve sorry, no need to use onProcess. Can you try the following example:
import 'dart:io';
import 'package:process_run/shell.dart';
void main(List<String> arguments) async {
var outController = ShellLinesController();
outController.stream.listen((event) {
stdout.writeln('[out]: $event');
});
var errController = ShellLinesController();
errController.stream.listen((event) {
stdout.writeln('[err]: $event');
});
var shell = Shell(
stdout: outController.sink,
stderr: errController.sink,
verbose: false,
throwOnError: false);
await shell.run('''
cmd /c echo "One line on stdout" \\
& echo "Another line on stdout" \\
& echo "One line on stderr" 1>&2 \\
& ping localhost
''');
It should display something like this (displayed in real time)
[out]: "One line on stdout"
[out]: "Another line on stdout"
[err]: "One line on stderr"
[out]:
[out]: Pinging xxxxx[::1] with 32 bytes of data:
[out]: Reply from ::1: time<1ms
[out]: Reply from ::1: time<1ms
[out]: Reply from ::1: time<1ms
[out]: Reply from ::1: time<1ms
[out]:
[out]: Ping statistics for ::1:
[out]: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
[out]: Approximate round trip times in milli-seconds:
[out]: Minimum = 0ms, Maximum = 0ms, Average = 0ms
thank
抱歉,我不确定您想要实现什么,无需使用 onProcess。您可以尝试以下示例吗:
import 'dart:io'; import 'package:process_run/shell.dart'; void main(List<String> arguments) async { var outController = ShellLinesController(); outController.stream.listen((event) { stdout.writeln('[out]: $event'); }); var errController = ShellLinesController(); errController.stream.listen((event) { stdout.writeln('[err]: $event'); }); var shell = Shell( stdout: outController.sink, stderr: errController.sink, verbose: false, throwOnError: false); await shell.run(''' cmd /c echo "One line on stdout" \\ & echo "Another line on stdout" \\ & echo "One line on stderr" 1>&2 \\ & ping localhost ''');
它应该显示类似这样的内容(实时显示)
[out]: "One line on stdout" [out]: "Another line on stdout" [err]: "One line on stderr" [out]: [out]: Pinging xxxxx[::1] with 32 bytes of data: [out]: Reply from ::1: time<1ms [out]: Reply from ::1: time<1ms [out]: Reply from ::1: time<1ms [out]: Reply from ::1: time<1ms [out]: [out]: Ping statistics for ::1: [out]: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), [out]: Approximate round trip times in milli-seconds: [out]: Minimum = 0ms, Maximum = 0ms, Average = 0ms
抱歉,我不确定您想要实现什么,无需使用 onProcess。您可以尝试以下示例吗:
import 'dart:io'; import 'package:process_run/shell.dart'; void main(List<String> arguments) async { var outController = ShellLinesController(); outController.stream.listen((event) { stdout.writeln('[out]: $event'); }); var errController = ShellLinesController(); errController.stream.listen((event) { stdout.writeln('[err]: $event'); }); var shell = Shell( stdout: outController.sink, stderr: errController.sink, verbose: false, throwOnError: false); await shell.run(''' cmd /c echo "One line on stdout" \\ & echo "Another line on stdout" \\ & echo "One line on stderr" 1>&2 \\ & ping localhost ''');
它应该显示类似的内容(实时显示)
[out]: "One line on stdout" [out]: "Another line on stdout" [err]: "One line on stderr" [out]: [out]: Pinging xxxxx[::1] with 32 bytes of data: [out]: Reply from ::1: time<1ms [out]: Reply from ::1: time<1ms [out]: Reply from ::1: time<1ms [out]: Reply from ::1: time<1ms [out]: [out]: Ping statistics for ::1: [out]: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), [out]: Approximate round trip times in milli-seconds: [out]: Minimum = 0ms, Maximum = 0ms, Average = 0ms
thank
hello process.stderr.transform and process.stdout.transform not have log?