Reputation: 11651
I am attempting to run a powershell script through the system command. This is the code I am using
status = system("start powershell.exe Set-ExecutionPolicy RemoteSigned \n");
status = system("start powershell.exe D:\\foo\\tempFilePShellCommand.ps1 > D:\\foo\\MyFile.txt");
Now the problem with the above code is that MyFile.txt gets created but its empty. If I run the file through powershell the file gets created and contains the correct data. Any suggestions on why the file is empty and how I can fix this /
Upvotes: 1
Views: 675
Reputation: 472
You need to specify that the parameter is a file. Otherwise, it is treated as a parameter to "PowerShell.exe" instead of a file you want to run using PowerShell.
status = system("start powershell.exe -File D:\\foo\\tempFilePShellCommand.ps1 > D:\\foo\\MyFile.txt");
Upvotes: 2