I have a powershell script which outputs a video file duration. Running this script gives me the expected result.
$Folder = 'C:\my\path\to\folder'
$File = 'sample1_1280_720.mp4'
$LengthColumn = 27
$objShell = New-Object -ComObject Shell.Application
$objFolder = $objShell.Namespace($Folder)
$objFile = $objFolder.ParseName($File)
$Length = $objFolder.GetDetailsOf($objFile, $LengthColumn)
Write-Output $Length
In a php file, I'm trying to save this output to a variable.
<?php
$var = shell_exec("powershell -File C:\my\path\to\psFile.ps1 2>&1");
echo "<pre>$var</pre>";
?>
The string output I get from shell_exec is the text you see when you start powershell from cmd. Windows PowerShell Copyright (C) 2016 Microsoft Corporation. All rights reserved. Any suggestions on how to extract the video duration?
Using your PS code
I'm able to get the file length using PS
-File
and-Command
. I added a few other flags you may want or need. You shouldn't need to use redirection2>&1
to get your variable from PS to PHP. It is most likely the reason you are getting the logo.Returning
$Length
in all three ways work for me