Using rector in an Windows environment

I'm having trouble running rector in an Windows environment. 

Windows 10

PhpStorm 2022.2

XAMPP (PHP 7.4.29)

rector 0.13.10, installed with composer, vendor/bin/rector init executed on cli. 

=> vendor directory is in the root. 

There is an issue in YouTrack, that request selecting an CLI-Interpreter. So I selected my php.exe.

With this setting, a right-click on a folder and "run rector" results in the command: 

E:\xampp\php\php.exe vendor/bin/rector process E:/xampp/htdocs/contentbroker/batch --output-format=json --dry-run

which outputs the content of the called script "endor/bin/rector", because it's not a php-Skript. 

dir=$(cd "${0%[/\\]*}" > /dev/null; cd "../rector/rector/bin" && pwd)

if [ -d /proc/cygdrive ]; then
    case $(which php) in
        $(readlink -n /proc/cygdrive)/*)
            # We are in Cygwin using Windows php, so the path must be translated
            dir=$(cygpath -m "$dir");

"${dir}/rector" "$@"

=> without the CLI setting the error just says: 

Error running 'batch': Cannot run program "vendor\bin\rector" (in directory "E:\xampp\htdocs\contentbroker"): CreateProcess error=2, System can't find file. 

Has anyone successfully run rector von Windows? Hat settings are neccessary? 

Regards: Chris

Comment actions Permalink

Sorry, not sure if understood the "installed with composer" part. Is it installed globally or you have it installed within the project?
btw, here is Rector on Windows with a `rector/rector` installed via the project `composer.json`:

Comment actions Permalink

Thank you for your quick reply. Yes, I installed rector in the project with composer,json.

Your screenshot is interesting. Looks like you defined your CLI-Interpreter c:\PHP806\php.exe. 
This calls


in my vendor/bin directory I have 




In my constallation the rector file (without extension) is executed, or parsed by the php-cli.which outputs it's content (the shell skript). 

So maybe your system autodetects that php-CLI shoud execute


instead of




Comment actions Permalink

Looks like I found the problem. Installed the environment on another machine and there it worked finde. So I checked the vendor/bin/rector file and found the content to be completly different :

#!/usr/bin/env php

 * Proxy PHP file generated by Composer
 * This file includes the referenced bin path (../rector/rector/bin/rector)
 * using a stream wrapper to prevent the shebang from being output on PHP<8
 * @generated

So obviously the problem is known, but the composer on my first machine installs a different, outdated rector version, also it's called 

   "require-dev": {
        "rector/rector": "^0.13.10"

on both machines... any idea, why composer acts different? 

Comment actions Permalink

In my case, "C:\PHP806\php.exe" was taken from the PHP CLI Interpreter IDE settings.
I wonder if it worth removing the 'vendor' folder from the affected project and run the "composer install" again, would it do the trick?

Comment actions Permalink

Problem solved. It needed a composer self-update and reinstall of rector/rector with the latest composer version to enable the PHP wrapper generation by composer for PHP Versions < 8.0. 


Please sign in to leave a comment.