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.

  • 2
    C:\....\data doesn't look right to me. .... cannot be a directory name.
    – DavidPostill
    May 16 at 21:42
  • no obviously thats a placeholder, I dont think everyone needs to know how my folders are organised...
    – Liron Chen
    May 17 at 7:57
  • Add switch -PassThru to the Start-Process cmdlet. From the docs "This cmdlet generates a System.Diagnostics.Process object, if you specify the PassThru parameter. Otherwise, this cmdlet does not return any output."
    – Theo
    May 17 at 9:05
  • Thank you Theo, however that didnt do the trick, still no output
    – Liron Chen
    May 20 at 10:12

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

  • Id like to use just Powershell and compile all the commands (Im using a list of about 20 at the moment), but its part of a series of events that are scheduled to run every hour. I never used Powershell, I didnt even know it existed.. can I somehow tie the Powershell prompt to Task Scheduler or is there a scheduler tied to PS? As far your command line, thank you for the input; however it again doesnt generate output. The command runs, like it did with my code, but doesnt write the file of parsed text..
    – Liron Chen
    May 20 at 10:11
  • @LironChen no worries, you can start powershell from a scheduled task and feed it a script to run like so: "Program to run: C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe" and "ArgumentList: -F C:\path\to\script.ps1". That said, it sounds like your program is running (powershell would error out if there was a bad path or no process). Is the parser supposed to take any parameters? Maybe it needs to be run from a specific directory? Is task scheduler running it as a different user?
    – Cpt.Whale
    May 20 at 16:33
  • its not supposed to take any parameters, its supposed to run in the directory its in as I copy it to each relevant folder before running it, and the scheduler runs a batch file so theyre all under the same umbrella I think. Ive solved it though by using batch commands: for /f %%i in ('dir /ad /od /b') do set LAST=%%i & cd %LAST% & Parser.exe & Which I could never get away with in a professional setting no doubt but it works so Im happy.
    – Liron Chen
    May 24 at 11:12

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.