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

Can not redirect standard output from bash read command prompt #140

Closed
my522cn opened this issue Feb 23, 2022 · 6 comments
Closed

Can not redirect standard output from bash read command prompt #140

my522cn opened this issue Feb 23, 2022 · 6 comments
Labels

Comments

@my522cn
Copy link

my522cn commented Feb 23, 2022

Version

3.4.1

Details

The 'read' shell script can not be redirect to StandardOutput.

Here's the C# code:

var cmd = Console.OpenStandardInput() | Cli.Wrap(path).WithStandardOutputPipe(PipeTarget.ToStream(Console.OpenStandardOutput()));
await cmd.ExecuteAsync();

Here's the shell code

#!/bin/bash
echo ""
echo ""
echo ""
echo ""
echo ""
echo "I'm #1"
read -t 3 -p "Ready for test press any key or wait for 3 s" k
echo "I'm #2"
read -t 3 -p "Ready for test press any key or wait for 3 s" k
echo "I'm #3"
read -t 3 -p "Ready for test press any key or wait for 3 s" k
echo "I'm #4"
read -t 3 -p "Ready for test press any key or wait for 3 s" k
RESULTFILE=./test.result
echo "PASS">${RESULTFILE}
ls

Snipaste_2022-02-23_17-24-56

"Ready for test press any key or wait for 3 s" was not printed

Steps to reproduce

As details above.

@my522cn my522cn added the bug label Feb 23, 2022
@Tyrrrz
Copy link
Owner

Tyrrrz commented Feb 23, 2022

Can you check if the same thing works using Process?

using var process = new Process
{
    StartInfo =
    {
        FileName = path,
        RedirectStandardOutput = true
    }
};

process.Start();
var output = process.StandardOutput.ReadToEnd();

@my522cn
Copy link
Author

my522cn commented Feb 24, 2022

Can you check if the same thing works using Process?

using var process = new Process
{
    StartInfo =
    {
        FileName = path,
        RedirectStandardOutput = true
    }
};

process.Start();
var output = process.StandardOutput.ReadToEnd();

it works using Process:
but without \n
Snipaste_2022-02-24_08-40-14

@Tyrrrz
Copy link
Owner

Tyrrrz commented Feb 24, 2022

I'd appreciate it if you can figure out where the bug is in CliWrap. I'm currently preoccupied with a war looming on the horizon. 🙁

@my522cn
Copy link
Author

my522cn commented Feb 24, 2022

It's incredibly challenging for me. I will PR if I figure the bug out.

@Tyrrrz Tyrrrz changed the title Can not redirect StandardOutput Can not redirect standard output from bash read command prompt Apr 4, 2022
@Tyrrrz
Copy link
Owner

Tyrrrz commented Apr 4, 2022

I did this in command line:

/bin/bash -c "echo test1; read -r -p test2; echo test3" > foo.txt

The output file contained only:

test1
test3

So it might be that's just how read works when stdout is redirected?

@Tyrrrz Tyrrrz added invalid and removed bug labels Apr 4, 2022
@Tyrrrz
Copy link
Owner

Tyrrrz commented Apr 4, 2022

Tested using System.Diagnostics.Process with the below code, the result is the same.

    using var process = new Process
    {
      StartInfo =
      {
          FileName = "/bin/bash",
          Arguments = "-c \"echo test1; read -r -p test2; echo test3\"",
          RedirectStandardOutput = true
      }
    };

    process.Start();
    var output = process.StandardOutput.ReadToEnd();

Closing as it doesn't seem to be a problem with CliWrap.

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

No branches or pull requests

2 participants