I'm trying to execute a PowerShell command via system()
command, but encounter an exception because of the spaces in the string, I tried a few things but still got the same exception.
Code:
system("powershell.exe -command Invoke-WebRequest http://example.com/myEXE.exe -OutFile C:\\Program Files\\myEXE.exe");
And this is the exception I get:
Invoke-WebRequest : A positional parameter cannot be found that accepts argument 'Files\myEXE.exe'. At line:1 char:1 + Invoke-WebRequest http://example.com/myEXE.exe -OutFile C:\Program File ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand