In the flown update of Windows 10 Creators Update, there was an interesting opportunity - to run Windows programs in this Linux. The official examples did not suit me completely - Microsoft evangelists suggested that I
draw a cow in PowerShell and run Notepad from bash . Che, right? Is this all you thought of?

As a person who was eagerly awaiting the ability to run exe-files inside WSL, I want to share the experience of using the new feature correctly.
I use Bash on Windows for every fine mechanization - deflate, parse, analyze. Take 10-20 gigs of logs and conjure over them in search of something like that. Take 200 gigs of source data, make the high-performance classes and pull a couple of mega results into the base of the site. In general, ordinary bytovuha like everyone else. Is not it so?
')
So my experience
Case number one
That's why I was waiting for the opportunity to run exe-files on WSL.
There are a number of websites for different programs, it is required to check that all the “download” links lead to the current versions.

Skipping the search for links and downloading files, let's move on to extracting the necessary information.
We do this in two ways.
The first path - appeal to WMIC
In CMD, the call for this information looks like this:wmic datafile where name="c:\\Windows\\System32\\cmd.exe" GET /VALUE
/ VALUE - to get all possible informationIn bash, it looks like this cmd.exe /C "wmic datafile where name='c:\\\\Windows\\\\System32\\\\cmd.exe' GET /VALUE"
slashes a lot and everything you needBut I need something not just to display on the screen, but to receive and process it.
Therefore, in PHP it looks like this:
/mnt/c/Windows/System32/cmd.exe is a full path to be sure
$ b is a multi-line result, so we get it as an array (only the last line falls into $ a)
$ ini - the result format is compatible with the ini-file, it’s not a sin to use - we turn the resulting $ b array into text for later conversion using parse_ini_string () .
The second way is using Scripting.FileSystemObject
I found this solution
here and dopilil a little.
In the original version there was a call for a short list with the results, which did not suit me WScript.Echo(objFolder.GetDetailsOf(objItem,-1));
I replaced this line with a loop extracting ALL possible file properties var folder=objShell.NameSpace(namespace); for (var i=0; i<0xFFFF; i++) { fileinfo=folder.GetDetailsOf(null, i); if (!fileinfo) { break; } WScript.Echo( fileinfo+" = "+objFolder.GetDetailsOf(objItem,i) ); }
output format is made compatible with ini-file.
The PHP code calling the bat file is like this. $q1="/mnt/c/Windows/System32/cmd.exe /C \"C:\\test_exe\\test_exe.bat ".addslashes($file)."\""; $a1=exec($q1,$b1); $ini1=implode("\n",$b1); $ini1=iconv("CP866","UTF-8", $ini1);
Almost the same as in the case of WMI, you only have to transcode the result to unicode. (CP866 - crying)
We glue the results into a single text and parsim $result_ini="[WMIC]\n".$ini."\n[FileSystemObject]\n".$ini1; $result_arr = parse_ini_string($result_ini, true, INI_SCANNER_RAW); print_r($result_arr);
We do partitioning (the second parameter is true) and in order to avoid problems we turn on - INI_SCANNER_RAWVZHUH and get an array of all possible properties of the file with which it is convenient to work. ~$ cd /mnt/c/test_exe/ /mnt/c/test_exe$ php test_exe.php
Array
(
[WMIC] => Array
(
[AccessMask] => 1179817
[Archive] => TRUE
[Caption] => c:\windows\system32\cmd.exe
[Compressed] => FALSE
[CompressionMethod] =>
[CreationClassName] => CIM_LogicalFile
[CreationDate] => 20170318235750.921718+180
[CSCreationClassName] => Win32_ComputerSystem
[CSName] =>
[Description] => c:\windows\system32\cmd.exe
[Drive] => c:
[EightDotThreeFileName] => c:\windows\system32\cmd.exe
[Encrypted] => FALSE
[EncryptionMethod] =>
[Extension] => exe
[FileName] => cmd
[FileSize] => 271872
[FileType] => Application
[FSCreationClassName] => Win32_FileSystem
[FSName] => NTFS
[Hidden] => FALSE
[InstallDate] => 20170318235750.921718+180
[InUseCount] =>
[LastAccessed] => 20170318235750.921718+180
[LastModified] => 20170318235750.921718+180
[Manufacturer] => Microsoft Corporation
[Name] => c:\windows\system32\cmd.exe
[Path] => \windows\system32\
[Readable] => TRUE
[Status] => OK
[System] => FALSE
[Version] => 10.0.15063.0
[Writeable] => TRUE
)
[FileSystemObject] => Array
(
[] => cmd.exe
[] => 265
[ ] =>
[ ] => 18.03.2017 23:57
[ ] => 18.03.2017 23:57
[ ] => 18.03.2017 23:57
[] => A
[] =>
[] =>
[ ] =>
[] => TrustedInstaller
[] =>
[ ] =>
[] =>
[] =>
[] =>
[] =>
[] =>
[] =>
[] =>
[] =>
[] =>
[] =>
[] =>
[] =>
[ ] => c Microsoft Corporation. All rights reserved.
[â„–] =>
[] =>
[ ] =>
[ ] =>
[, ] =>
[] =>
[, ] =>
[] => Microsoft Corporation
[ ] => Windows Command Processor
[ ] =>
[ ] =>
[] =>
[ ] =>
[] =>
[] =>
[ ] =>
[ ] =>
[ ] =>
[ ] =>
[ ] =>
[ ] =>
[ ] =>
[] =>
[ ] =>
[/] =>
[ ] => 227
[ ] =>
)
)
What was all this stromnok? But to what.
As I mentioned earlier, on the Microsoft website, we were told that now we can draw cows in PowerShell and run notepad.exe from the tower.
And in the discussion of the
translation of this Maykrosoftovsky text, people find out how honest Linux is there and whether it is possible to pile on Docker on it.
People, you're not looking there! I executed a
PHP script in
bash which, through
exec (), launched the
bat file in which
JScript created
ActiveXObject .
It's Kind Of Magic!
And I can do this from CMD like this: C:\test_exe>bash -c "php test_exe.php"
Aaaaaaaa!
Case number two
Update Windows 10 Creators Update I rolled on the 6th, and last week I was distracted from the new toy by the accounting department. Accounting requested originals originals.
Eureka, I thought, and put the console typing
We climb in bash and just run the program ~$ 2Printer.exe -s "c:\2Printer\_input\*.*"
The result - the leaves of the printer are crawling:
(this screenshot is a subsequent imitation on a virtual printer, but on a real HP it worked too)As a result, we have:
- the program showed interactivity (the test requested to press a button)
- from bashyovskogo window climbed on its wind paths
- took from there files with Russian names
- called the office editor via COM objects
- sent result to printer
That is, you can not only write simple scripts, but also use complex programs.
Summary
I have not fully realized what else can be done with this, but this thing can be much more than just talking to cows and launching LAMP.
You just have to allow yourself to break out of the “either Linux or Windows” dichotomy and begin to cross hedgehogs and snakes in the most incredible proportions and sequences.