Why doesnt the executable I run through powershell generate output?

Ive written a text parser in C++ that runs fine from a command line. I'm trying to include it in a batch file of Powershell API calls, to convert the received data right away. I realise this is probably circumvent but I'm a student and just getting the hang of automating my (continuously repeating) data retrieval process.

The problem is that the .exe doesn't write the output file, the parsed text. Ive tried a few ways, currently I'm at:

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

I'm doing it this way since setting my location to the directory that the data is downloaded in every hour hasn't worked for some reason, I'm OK with manually pointing to it. I can see that the .exe does run, but without result.

Am I not phrasing it correctly? Or do I need to specify that this .exe creates output? It writes weather data into a .txt.

I have very little experience with powershell btw, I barely know what I'm doing, but I just want to run this .exe and maybe another one I'll write to call a third party app to convert the .txt to another format.

4

1 Answer

I recommend running everything in powershell if possible - CMD/batch has some different parsing rules which can cause issues, especially with quoted parameters/paths and certain symbols. That being said, you can run your command properly like this:

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

Start-Process takes the place of 'Call'/&, so that can be removed

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like