Commit graph

10 commits

Author SHA1 Message Date
Brad Jorsch
86cfcfdbba Shell: Don't hang on empty stdin
If the write buffer for a file descriptor is empty, don't try to write
to it. Just close it and continue on.

Bug: T188019
Change-Id: Ie5b5ac1ef1aec4ae763cf4d0d58d3a28e42b7d2a
2018-02-22 17:13:28 -05:00
Umherirrender
63d96c15fd build: Updating mediawiki/mediawiki-codesniffer to 16.0.0
Change-Id: I59b59f79bbf3ce4feff3b3a20c1c31bc16370531
2018-02-17 13:29:13 +01:00
Gergő Tisza
0e211c4f29 Allow programmatic input in Command
Bug: T182463
Change-Id: Ib68180c7af12558686f4864c24fd85f01201d6fb
2018-01-03 19:53:47 +03:00
Kunal Mehta
75160bdd3b Use MediaWikiCoversValidator for tests that don't use MediaWikiTestCase
Change-Id: I8c4de7e9c72c9969088666007b54c6fd23f6cc13
2018-01-01 08:28:02 +00:00
Kunal Mehta
f4fb48d01c Add @covers for includes/shell/ tests
Change-Id: I495c64622f39ad7e0343e8341771d5a4a3449e97
2017-12-08 22:08:28 -08:00
Max Semenik
36009e3ca7 Shell: skip null parameters
Right now they're treated as empty strings, however
this doesn't allow skipping parameters in the middle like
 $params = [
     'foo',
     $x ? '--bar' : null,
     '--baz',
 ];

In some cases this matters, e.g. `ls` works while `ls ''` doesn't.

Also, fix spacing problems the new tests uncovered:
* Extra space when using params()
* Missing space when combining params() and unsafeParams()

Change-Id: Icb29d4c48ae7f92fb5635e3865346c98f47abb01
2017-11-29 12:38:35 -08:00
Gergő Tisza
7d9dbc0040
MediaWiki\Shell: log stderr
Change-Id: I1495fe2aba10102d7e36c3a3e5fdabf97f14546b
2017-10-26 21:06:03 -07:00
Max Semenik
4d9a95f970 Don't trigger PHP errors for unused Shell\Command
Change-Id: Id29da4f21a44ccb18d8a2ae11348d69ca3233aa5
2017-10-17 18:55:11 -07:00
Max Semenik
926c97c69f
Return stderr from Shell\Command
Change-Id: I5551ae4bbe7b539b528a734aa82198b11f103871
2017-10-12 02:12:20 -07:00
Max Semenik
77ce3b98a0 Replace wfShellExec() with a class
This function has gotten so unwieldy that a helper was
introduced. Instead, here's this class that makes
shelling out easier and more readable.

Example usage:
  $result = Shell::command( 'shell command' )
       ->environment( [ 'ENVIRONMENT_VARIABLE' => 'VALUE' ] )
       ->limits( [ 'time' => 300 ] )
       ->execute();

  $exitCode = $result->getExitCode();
  $output = $result->getStdout();

This is a minimal change, so lots of stuff remains
unrefactored - I'd rather limit the scope of this commit.
A future improvement could be an ability to get stderr
separately from stdout.

Caveat: execution errors (proc_open is disabled/returned error) now
throw errors instead of returning a status code. wfShellExec() still
emulates this behavior though.

Competing commit: I7dccb2b67a4173a8a89b035e444fbda9102e4d0f
<legoktm> MaxSem: so you should continue working on your patch and I'll
          probably refactor on top of it later after its merged :P

Change-Id: I8ac9858b80d7908cf7e7981d7e19d0fc9c2265c0
2017-09-08 21:49:49 -07:00