I have installed Apache web server Apache/2.4.25 (Win32) with mod_fcgid/2.3.9
Then I have a file test.cgi in cgi-bin folder with following 3 lines:
#!“C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe” -NoLogo -ExecutionPolicy unrestricted
“HTTP/1.1 200 OK`r`nContent-Type: text/plain`r`n`r`n”
When I put the http://localhost/cgi-bin/test.cgi into browsers address bar, the response is
In the apache\logs\error.log is
[Thu Nov 30 18:20:29.215223 2017] [cgi:error] [pid 3548:tid 1680] [client ::1:55927] End of script output before headers: te
How can I fix it?
You’re VERY outside of PowerShell’s envisioned use cases, here - so it might never work the way you want. And I suspect it’ll be dog-slow if it does work.
But running PowerShell that way wouldn’t work anyway, I don’t think. First, you’ve just run PowerShell - you’ve not told it to do anything, like run a script. Second, I’m not really sure PowerShell would output to stdout in the way you’re thinking, although I’m not sure what you’re goal is, so I might be wrong on that.
Currently I use cmd scripts and Perl scripts to do some jobs. They are launched by clicking on a web page link or a button. For example one script zips a selected folder and lets the user to download it. But I have many other such scripts. I think Powershell is cleaner language, more “future” and natural in Windows. Currently run the .bat and .ps1 from Perl script, but it is not what I like to do. The test.ps1 script mentioned above should only write Hello in the browser - to test the concept.