Skip to content

[Process] Introduce InputStream and iterator for output #6424

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

Closed
wants to merge 1 commit into from

Conversation

nicolas-grekas
Copy link
Member

Q A
Doc fix? no
New docs? yes
Applies to 3.1
Fixed tickets -

is closed.

In order to write to a subprocess standard input while it is running, the component
provides the :class:`Symfony\\Component\\Process\\InputStream` class.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

documenting its usage is necessary

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about the say the same. A small practical example would help a lot.

@stof
Copy link
Member

stof commented Apr 1, 2016

I think it might be time to split the doc of the Process component into multiple chapters, an dhaving one such chapter dedicated to the way to deal with the input (with basic examples and more complex ones)

fabpot added a commit to symfony/symfony that referenced this pull request Apr 2, 2016
…rocesses (nicolas-grekas)

This PR was merged into the 3.1-dev branch.

Discussion
----------

[Process] Add InputStream to seamlessly feed running processes

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18262
| License       | MIT
| Doc PR        | symfony/symfony-docs#6424

Look at the tests, beautiful, isn't it?

Commits
-------

3d20b6c [Process] Add InputStream to seamlessly feed running processes
symfony-splitter pushed a commit to symfony/process that referenced this pull request Apr 2, 2016
…rocesses (nicolas-grekas)

This PR was merged into the 3.1-dev branch.

Discussion
----------

[Process] Add InputStream to seamlessly feed running processes

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18262
| License       | MIT
| Doc PR        | symfony/symfony-docs#6424

Look at the tests, beautiful, isn't it?

Commits
-------

3d20b6c [Process] Add InputStream to seamlessly feed running processes
@linaori
Copy link
Contributor

linaori commented Apr 2, 2016

I think @stof has a valid point here, the process page is already rather big compared to some others.

@fabpot
Copy link
Member

fabpot commented Apr 3, 2016

Don't forget to also document "IteratorAggregate to stream output" from symfony/symfony#18414

fabpot added a commit to symfony/symfony that referenced this pull request Apr 3, 2016
… (nicolas-grekas)

This PR was merged into the 3.1-dev branch.

Discussion
----------

[Process] Implement IteratorAggregate to stream output

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | symfony/symfony-docs#6424

Sibling to #18386 for iterating of the output streams.

Commits
-------

5947f5d [Process] Implement IteratorAggregate to stream output
@nicolas-grekas nicolas-grekas changed the title [Process] Introduce InputStream [Process] Introduce InputStream and iterator for output Apr 3, 2016
@nicolas-grekas nicolas-grekas force-pushed the process-31 branch 2 times, most recently from 6a7eb39 to 0c8e0d0 Compare April 3, 2016 17:05
@nicolas-grekas
Copy link
Member Author

PR updated, LGTM. Do you think it needs more content?
Comments welcomed. If someone is willing to help and do the split @stof suggests in a later PR, I'd be thankful for it...


The :method:`Symfony\\Component\\Process\\Process::clearOutput` method clears
the contents of the output and
:method:`Symfony\\Component\\Process\\Process::clearErrorOutput` clears
the contents of the error output.

You can also use the :class:`Symfony\\Component\\Process\\Process` class with the
foreach construct to get the output while it is generated. By default, the loop waits
for new outputs before going to the next iterations::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

output, iteration?

@fabpot
Copy link
Member

fabpot commented Apr 3, 2016

👍

echo $process->getOutput();

The :method:`Symfony\\Component\\Process\\InputStream::write` method accepts scalars,
stream resources or Traversable objects as argument. As shown is the above example,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As shown is the -> As shown in the

@@ -128,6 +143,46 @@ are done doing other stuff::
which means that your code will halt at this line until the external
process is completed.

Feeding the standard input of a Process
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Streaming instead of Feeding ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Feeding" sounds good to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Standard" and "Input" should be uppercased.

@javiereguiluz
Copy link
Member

👍

@nicolas-grekas thanks for these docs!

@@ -43,13 +43,28 @@ The ``getOutput()`` method always returns the whole content of the standard
output of the command and ``getErrorOutput()`` the content of the error
output. Alternatively, the :method:`Symfony\\Component\\Process\\Process::getIncrementalOutput`
and :method:`Symfony\\Component\\Process\\Process::getIncrementalErrorOutput`
methods returns the new outputs since the last call.
methods return the new output since their last call.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make this fix in all affected lower branches too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #6658

@xabbuh
Copy link
Member

xabbuh commented Apr 10, 2016

We need a versionadded directive for the features that are new in Symfony 3.1.


Before a process is started, you can specify its standard input using either the
:method:`Symfony\\Component\\Process\\Process::setInput` method or the 4th argument
of the Process constructor. The provided input can be a string, a stream resource or
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"of the constructor."

@wouterj
Copy link
Member

wouterj commented Jun 11, 2016

Hi @nicolas-grekas! Can you please finish this PR? Otherwise, just say it and we'll fix the minor issues while merging.

@nicolas-grekas
Copy link
Member Author

Comments addressed hopefully (I'll let you guys split this into several pages...)

@@ -68,6 +83,10 @@ with a non-zero code)::
echo $e->getMessage();
}

.. versionadded:: 3.1
Streaming the input or the output of a process using iterators
were added in Symfony 3.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should split this.

Above the paragraph added above:

.. versionadded:: 3.1
    Support for streaming the output using iterators was introduced
    in Symfony 3.1.

After the "Streaming to the standard input of a Process" headline:

    Support for streaming the input of a process was introduced in
    Symfony 3.1.

@@ -128,6 +147,46 @@ are done doing other stuff::
which means that your code will halt at this line until the external
process is completed.

Streaming to the standard input of a Process
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Streaming to the Standard Input of a Process

@xabbuh
Copy link
Member

xabbuh commented Jun 18, 2016

👍 except of the minor comments above (but we can address them while merging)

Status: Reviewed

@xabbuh
Copy link
Member

xabbuh commented Jun 30, 2016

ping @javiereguiluz @weaverryan @wouterj

@wouterj
Copy link
Member

wouterj commented Jul 2, 2016

Thanks @nicolas-grekas! Fyi, I've rebased this PR in #6705 and merged that one.

@wouterj wouterj closed this Jul 2, 2016
wouterj added a commit that referenced this pull request Jul 2, 2016
… (nicolas-grekas)

This PR was merged into the 3.1 branch.

Discussion
----------

[Process] Introduce InputStream and iterator for output

Rebase of #6424

Commits
-------

51ac1a6 [Process] Introduce InputStream and iterator for output
@nicolas-grekas nicolas-grekas deleted the process-31 branch July 24, 2016 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants