After using Powershell to run an executable, why does that exe not generate its output?

L. Chen 1 Reputation point

I have a set of Powershell commands that I need to run every hour. Some retrieve data, then I want to run a parser I wrote in C++, and Ill want to export the output from that to another location.
The problem is that the parser doesnt write its output file when called through PS. I can see that it runs, but no files are generated by. It does work fine when just manually run through windows or cmd.
Does anyone know why that is? Ive tried both of these commands:

powershell.exe -command "& {$exePath = Join-Path -Path 'C:....\data' -ChildPath ('\abcd_{0:MM-dd-HH}\Parser.exe' -f (Get-Date));$client = Start-Process -FilePath $exePath -wait}"


powershell.exe -Command Start-Process -FilePath "C:...\data\abcd$(Get-Date -f MM-dd-HH)\Parser.exe" -wait -passthru

Where C:...\ and abcd are just placeholders for the actual path and filename that I use. Both these lines run the parser but neither allows it to create output.
Im running all the commands from a .bat that I run through Task Scheduler. I know thats suboptimal and Ill look into other ways like a .ps1 etc, but when I run it from within Powershell itself they also dont work. If that will be the deciding factor I can move away from the .bat but Id first like to find a way to make it work at all.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,273 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 27,431 Reputation points Microsoft Vendor


    I tested a .bat file of the below command as a scheduled task and the output file was generated as expected. The test.exe is a simple executable that just outputs to a text file.

    powershell.exe -Command Start-Process -FilePath D:\abcd$(Get-Date -f MM-dd-HH)\test.exe -wait -passthru  

    Best Regards,
    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments