Skip to content

Q: how to pass a string as stdin to Runners' run()? #7145

Description

@adswa

The docstring of the Runner's run method state the following about the stdin= parameter:

stdin : file-like, string, bytes, Queue, or None
If stdin is a file-like, it will be directly used as stdin for the
subprocess. The caller is responsible for writing to it and closing it.
If stdin is a string or bytes, those will be fed to stdin of the
subprocess. If all data is written, stdin will be closed.
If stdin is a Queue, all elements (bytes) put into the Queue will
be passed to stdin until None is read from the queue. If None is read,
stdin of the subprocess is closed.

However, if I provide a string to it (I tried toying around in the context of #6514), I get

Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/home/adina/repos/datalad/datalad/runner/runnerthreads.py", line 172, in run
    succeeded = self.write(data)
  File "/home/adina/repos/datalad/datalad/runner/runnerthreads.py", line 246, in write
    written += os.write(
TypeError: a bytes-like object is required, not 'str'

I feel like I might be missing something fairly obvious. How can I provide a string as stdin to a runner.run() call?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    severity-normalstandard severityteam-runnersub-process execution and IO (https://github.com/datalad/datalad/issues/6365)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions