2

For all my years running PHP CLI on Windows, I have started my scripts with .bat files like this:

php test.php

php resolves to C:\PHP\php.exe due to my PATH.

No problems with this. Except they always get that pesky cmd.exe icon/Taskbar group.

So, just a few minutes ago, I instead created a shortcut on my desktop directly to C:\PHP\php.exe, and entered the full path to my script as an argument to it. Now, when I double-click that "PHP" icon on my desktop, it opens not cmd.exe, but PHP.exe directly, so that it gets a PHP icon instead of cmd.exe icon, and puts itself in its own Taskbar group.

However, besides the icon, it looks identical in every other way to cmd.exe. I'm pretty sure that it is cmd.exe, just with the PHP icon. Or is this some kind of custom terminal, entirely separated from cmd.exe?

There is also a php-win.exe executable in C:\PHP. I've never been able to figure out what this is or how it differs from php.exe in the same dir. If I do the same thing as above with it, it instantly crashes with the logged PHP error:

cli_get_process_title(): cli_get_process_title had an error: Windows error code: 6

There is no mention whatsoever in the "README" file about this executable.

I have many times experimented with and tried to use PowerShell, but there is always weird glitches and issues with it, which is why I've stuck to cmd.exe. Also, having to make a ton of shortcuts all the time and edit their arguments to represent the full paths to my PHP scripts is much worse than having .bat files which run my PHP scripts in a much nicer manner, albeit with the pesky cmd.exe icon instead of the PHP one.

This "Windows Terminal" thing I've seemingly heard about for years, but it's still nowhere to be found on my machine.

Ideally, I would want to be able to have my own custom icon, neither taken from cmd.exe nor php.exe, but the only way I've found to do that in the past is to copy cmd.exe, modify it and then use that everywhere. That is not an elegant or sensible solution.

Please explain to me what php-win.exe is for, whether php.exe is actually just cmd.exe with a different icon, and if there is something simple I can do to get my own icon/branding for my PHP CLI system.

1

1 Answer 1

3

No problems with this. Except they always get that pesky cmd.exe icon/Taskbar group.

They will, because .bat scripts are always run through cmd.exe (like – so they get whatever console window cmd.exe itself gets.

However, besides the icon, it looks identical in every other way to cmd.exe. I'm pretty sure that it is cmd.exe, just with the PHP icon. Or is this some kind of custom terminal, entirely separated from cmd.exe?

The terminal has always been separate from cmd.exe. You're looking at the standard Windows Console window, now also known as Conhost. (In Win2000/XP era it was part of CSRSS.)

Both cmd.exe and php.exe have no graphical user interface of their own – they just magically invoke Conhost when started.

There is also a php-win.exe executable in C:\PHP. I've never been able to figure out what this is or how it differs from php.exe in the same dir.

As mentioned, php.exe invokes the Conhost terminal window when started – but that isn't something php.exe does, it actually happens automatically because Windows recognizes that the php.exe file is marked as "console application". It will always get launched in a console, whether it's one inherited from cmd.exe (when running a .bat script) or whether it's a new one (when double-clicking php.exe).

So php-win.exe is almost exactly the same thing, but the .exe file is not marked as "console" – it's marked as "GUI application" instead, and will run completely invisible (unless you use it to run a script that e.g. calls PHP-GTK or PHP/Tk to create GUI windows).

For the same reason, Python comes with python.exe and pythonw.exe on Windows – one is for building primarily CLI-based tools, the other for building graphical apps.

This "Windows Terminal" thing I've seemingly heard about for years, but it's still nowhere to be found on my machine.

It's installable through the Microsoft Store if you have Windows 10.

(Note that if you install it, it won't replace Conhost completely – it will only be used when you open the Terminal app yourself. Double-clicking on a console .exe will still display it in Conhost.)

Ideally, I would want to be able to have my own custom icon, neither taken from cmd.exe nor php.exe, but the only way I've found to do that in the past is to copy cmd.exe, modify it and then use that everywhere. That is not an elegant or sensible solution.

Copy php.exe and modify that one. Or use php-win.exe together with some PECL module (maybe w32api) that allows you to create a console window on demand.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .