Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process listen invalid #111

Open
qq1100 opened this issue Oct 29, 2024 · 7 comments
Open

process listen invalid #111

qq1100 opened this issue Oct 29, 2024 · 7 comments

Comments

@qq1100
Copy link

qq1100 commented Oct 29, 2024

hello process.stderr.transform and process.stdout.transform not have log?

@qq1100
Copy link
Author

qq1100 commented Oct 29, 2024

Received upon completion of task execution log,solution?

@alextekartik
Copy link
Contributor

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 (

var controller = ShellLinesController();
var shell = Shell(stdout: controller.sink, verbose: false);
) that provides an easy way to listen to streamed lines from either stdout or stdin

@qq1100
Copy link
Author

qq1100 commented Oct 30, 2024

我不完全理解这个问题,但如果你想监听 stdout/strerr 流,你必须创建一个控制器。有一个完全没有记录的 ShellLinesController (

var controller = ShellLinesController();
var shell = Shell(stdout: controller.sink, verbose: false);

) 提供了一种简单的方法来监听来自 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

@alextekartik
Copy link
Contributor

alextekartik commented Oct 30, 2024

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.

@qq1100
Copy link
Author

qq1100 commented Oct 30, 2024

我不知道您正在生成哪个应用程序,以及它是否有输出(许多 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

@alextekartik
Copy link
Contributor

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

@qq1100
Copy link
Author

qq1100 commented Oct 30, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants