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

fix(Process): Convert command to array format #174

Merged
merged 2 commits into from Nov 27, 2019
Merged

fix(Process): Convert command to array format #174

merged 2 commits into from Nov 27, 2019

Conversation

Quynh-Nguyen
Copy link
Contributor

When upgrade dependency symfony/process to version ^5.0

We will got this error:

Fatal error: Uncaught TypeError: Argument 1 passed to Symfony\Component\Process\Process::__construct() must be of the type array, string given, called in /root/.composer/vendor/laravel/envoy/src/RemoteProcessor.php on line 62 and defined in /root/.composer/vendor/symfony/process/Process.php:140

So this pull request for resolve this issue.

I was tested on my local.

@driesvints
Copy link
Member

Released v1.6.3 with this.

@crynobone
Copy link
Member

https://symfony.com/doc/current/components/process.html#using-a-prepared-command-line

I think it would be more appropriate to use Process::fromShellCommandline()

@Quynh-Nguyen
Copy link
Contributor Author

@crynobone
Yes that's also one option.
But I don't want to break the source code structure too much.

@crynobone
Copy link
Member

crynobone commented Nov 28, 2019

@Quynh-Nguyen I just happen to have faced with the same issue on my project using symfony/process and converting it to array doesn't work.

use Symfony\Component\Process\Process;

require "vendor/autoload.php";

$command = "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version";
$script = explode(' ', $command);
$process = new Process($script);
$process->mustRun();
PHP Fatal error:  Uncaught Symfony\Component\Process\Exception\ProcessFailedException: The command "'/Applications/Google\' 'Chrome.app/Contents/MacOS/Google\' 'Chrome' '--version'" failed.

Exit Code: 126(Invoked command cannot execute)

Working directory: /Users/miki/Projects/orchestra/dusk-updater

Output:
================


Error Output:
================
sh: /Applications/Google\: No such file or directory
sh: line 0: exec: /Applications/Google\: cannot execute: No such file or directory
 in /Users/miki/Projects/orchestra/dusk-updater/vendor/symfony/process/Process.php:250
Stack trace:
#0 /Users/miki/Projects/orchestra/dusk-updater/example.php(10): Symfony\Component\Process\Process->mustRun()
#1 {main}
  thrown in /Users/miki/Projects/orchestra/dusk-updater/vendor/symfony/process/Process.php on line 250

Fatal error: Uncaught Symfony\Component\Process\Exception\ProcessFailedException: The command "'/Applications/Google\' 'Chrome.app/Contents/MacOS/Google\' 'Chrome' '--version'" failed.

Exit Code: 126(Invoked command cannot execute)

Working directory: /Users/miki/Projects/orchestra/dusk-updater

Output:
================


Error Output:
================
sh: /Applications/Google\: No such file or directory
sh: line 0: exec: /Applications/Google\: cannot execute: No such file or directory
 in /Users/miki/Projects/orchestra/dusk-updater/vendor/symfony/process/Process.php:250
Stack trace:
#0 /Users/miki/Projects/orchestra/dusk-updater/example.php(10): Symfony\Component\Process\Process->mustRun()
#1 {main}
  thrown in /Users/miki/Projects/orchestra/dusk-updater/vendor/symfony/process/Process.php on line 250

I only manage to solve the issue by changing it to Process::fromShellCommandline(). So I don't know how extensive the use of process in envoy and whether or not anything similar needed.

@Quynh-Nguyen
Copy link
Contributor Author

@crynobone
This is the reason:

Google\ Chrome.app

@driesvints
Copy link
Member

Urgh, I'll get that fixed in a bit.

@Quynh-Nguyen
Copy link
Contributor Author

@driesvints
Can I create new pull request for resolve the case run script on localhost case?

@crynobone
Copy link
Member

$process = new Process(["/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome", "--version"]);
$process->mustRun();

Trying to be smart and do it manually also return the same error.

PHP Fatal error:  Uncaught Symfony\Component\Process\Exception\ProcessFailedException: The command "'/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome' '--version'" failed.

Exit Code: 126(Invoked command cannot execute)

Working directory: /Users/miki/Projects/orchestra/dusk-updater

Output:
================


Error Output:
================
sh: /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome: No such file or directory
sh: line 0: exec: /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome: cannot execute: No such file or directory
 in /Users/miki/Projects/orchestra/dusk-updater/vendor/symfony/process/Process.php:250
Stack trace:
#0 /Users/miki/Projects/orchestra/dusk-updater/example.php(8): Symfony\Component\Process\Process->mustRun()
#1 {main}
  thrown in /Users/miki/Projects/orchestra/dusk-updater/vendor/symfony/process/Process.php on line 250

Fatal error: Uncaught Symfony\Component\Process\Exception\ProcessFailedException: The command "'/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome' '--version'" failed.

Exit Code: 126(Invoked command cannot execute)

Working directory: /Users/miki/Projects/orchestra/dusk-updater

Output:
================


Error Output:
================
sh: /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome: No such file or directory
sh: line 0: exec: /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome: cannot execute: No such file or directory
 in /Users/miki/Projects/orchestra/dusk-updater/vendor/symfony/process/Process.php:250
Stack trace:
#0 /Users/miki/Projects/orchestra/dusk-updater/example.php(8): Symfony\Component\Process\Process->mustRun()
#1 {main}
  thrown in /Users/miki/Projects/orchestra/dusk-updater/vendor/symfony/process/Process.php on line 250

@driesvints
Copy link
Member

@crynobone @Quynh-Nguyen I released v1.6.4 which used fromShellCommandline instead. Can you try that one?

@crynobone
Copy link
Member

Screenshot 2019-11-28 at 7 41 34 PM

Screenshot 2019-11-28 at 7 42 00 PM

@driesvints
Copy link
Member

@crynobone thanks for verifying 👍

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

Successfully merging this pull request may close these issues.

None yet

4 participants