1

Using:

  • Laravel 8
  • PHP 8.0 (homebrew)

Problem: Running any shell commands using Symfony: Symfony\Component\Process\Process

The following code executes on php7.4, but not on php8.0, both within Laravel 8

        $newDir = storage_path('test');
        $process1 = new Process(["mkdir ". $newDir]);
        $process1->run();

        if (! $process1->isSuccessful()) {
            throw new ProcessFailedException($process1);
        }

The result on PHP 7.4 is that the test directory is created within Laravels storage directory.

The result on PHP 8.0 is that the exception ProcessFailedException is triggered, with the result.

Error Output:
================
sh: /Users/username/code/project-name/mkdir /Users/username/code/project-name/storage/test: No such file or directory
sh: line 0: exec: /Users/username/code/project-name/mkdir /Users/username/code/project-name/storage/test: cannot execute: No such file or directory

I have attempted to use other commands and all give the same result

cannot execute: No such file or directory

My suspicion is that it may be permissions related, but all related processes can be seen running as the user executing the process. What am i missing?

0

1 Answer 1

1

Use a full path i.e. /bin/mkdir and separate the arguments instead of mkdir plus string concatenation.

$process1 = new Process(["/bin/mkdir", "-p", $newDir]);

The Process component can't find an executable with name mkdir [arguments] in your current working directory.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, the relative directory did the trick. I can now work out how to run the other commands i need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.