I have a powershell script that is supposed to be started by php like this:
$hashingCommand = "start powershell -file C:\Apache24\htdocs\\runHashCalc.ps1 \\\\$sAddr \\\\$dAddr $name $algorithm";
pclose(popen($hashingCommand, 'r'));
which leads to something like this:
C:\>WMIC path win32_process get Caption,ProcessId,Commandline | findstr "testingCopyJob"
powershell.exe powershell -file C:\Apache24\htdocs\runHashCalc.ps1 \\ACTUALPATH\netstorage\User \\ACTUALPATH\netstorage\copyfolder testingCopyJob sha256 5036
However the script does not do what it is supposed to do.
If I start the script with the exact same parameters from the commandline it works perfectly fine though.
C:\>powershell -file C:\Apache24\htdocs\runHashCalc.ps1 \\ACTUALPATH\netstorage\User \\ACTUALPATH\netstorage\copyfolder testingCopyJob sha256
\\config.sample.inc.php
sha256
mariadb --user=username --password=******* -e 'INSERT INTO testingCopyJob (file_name,hash) VALUES (' \\config.sample.inc.php',' 8AA4CE89D12978E805C6A128745A1A885A1E6523220C6647886DC74DC13F421A')' *****_xsw
[...]
The powershell script itself looks like this:
[...]
gci -af -rec $sourceFolder | Foreach-Object {
$cmd = Get-FileHash $_.FullName -Algorithm $algorithm | Format-List
$asString = $cmd | ft | out-string
$answerArray = $asString.Split([System.Environment]::NewLine,[System.StringSplitOptions]::RemoveEmptyEntries)
$hash = $answerArray[1].Split(":")[1]
$path = $answerArray[2] -split ':',2
$aPath = $path[1]
$aPath=$aPath.Replace($sourceFolder,'')
$aPath=$aPath.Replace('\','\\')
write-host $aPath | Out-File -FilePath C:\Apache24\htdocs\hashlog.log -Append
write-host $algorithm | Out-File -FilePath C:\Apache24\htdocs\hashlog.log -Append
write-host "mariadb --user=user --password=******* -e 'INSERT INTO $name (file_name,hash) VALUES ('$aPath','$hash')' *****_xsw" | Out-File -FilePath C:\Apache24\htdocs\hashlog.log -Append
$answer = mariadb --user=user --password=******* -e "INSERT INTO $name (file_name,hash,source) VALUES ('$aPath','$hash',0)" *****_xsw
write-host $answer | Out-File -FilePath C:\Apache24\htdocs\hashlog.log -Append
}
[...]
(Not even the logging works like this Out-File -FilePath C:\Apache24\htdocs\hashlog.log -Append
but that's also the case when running from cmd).
Any ideas on why this happens are welcome.
EDIT: Log works with write-output
instead of write-host