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

Use with StringIO #183

Closed
alexeyr-ci1 opened this issue Sep 16, 2022 · 2 comments
Closed

Use with StringIO #183

alexeyr-ci1 opened this issue Sep 16, 2022 · 2 comments
Labels

Comments

@alexeyr-ci1
Copy link

The basic example says

# ...or pass an IO
process.io.stdout = Tempfile.new("child-output")

This sounds like a StringIO should work. But

irb(main):001:0> p = ChildProcess.build("ls")
=> #<ChildProcess::Unix::PosixSpawnProcess:0x000055e6766ab500 @args=["ls"], @started=false, @exit_code=nil, @io=nil, @cwd=nil, @detach=false, @dupl...  
irb(main):002:0> p.io.stdout = StringIO.new
Traceback (most recent call last):
        1: from (irb):2
ArgumentError (expected #<StringIO:0x000055e6799b3448> to respond to :to_io)
@sds sds added the bug label Jan 7, 2024
@sds
Copy link
Collaborator

sds commented Jan 7, 2024

This may still be an issue, but since #175 made a lot of low-level changes, this may have been resolved.

If you're still seeing this problem, feel free to open a new issue. Thanks!

@eregon
Copy link
Contributor

eregon commented Jul 22, 2024

It's not possible to spawn a subprocess and have it write directly to a StringIO:

> system 'uname', out: StringIO.new
(irb):6:in `system': wrong exec redirect action (ArgumentError)

So this cannot be supported directly.

If you need it you can write to a Tempfile, wait the process, copy from the tempfile to the StringIO or whatever, and close the Tempfile.

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

3 participants