简体   繁体   中英

Running executables in Powershell with complex arguments

I am working on converting an old massive batch file logging script to Powershell. Creating the data has not been a major issue, but I am having an issue with the final step. The final step in the old batch file converts an ugly CSV into a more pretty and easy-on-the-eyes CSV. This is done using an old AWK script and a gawk command. I am content leaving that step in place, but I want it to be executed from within the Powershell script.

The command looks something like this:

<gawk.exe> -f <path>\PrepareReport.awk <original.csv> >> <final.csv>

I have tried different ways of calling gawk and the arguments. Invoke-Expression, Invoke-Command, etc. Nothing seems to work to run this command properly. Any insight or ideas would be appreciated.

Thanks!

EDIT: Following all the comments, I have found the & is the option that works to make this happen. The Start-Process cmdlet causes a fatal error. One weird thing is still happening though. For some reason the resulting CSV file does not display normally in Excel. Even though the resulting file seems to be perfectly normal, Excel won't display it using the appropriate comma breaks. Any thoughts?

You could always use Start-Process.

Start-Process -NoNewWindow -Wait -PassThru -FilePath <gawk.exe> -ArgumentList "-f <path>\PrepareReport.awk <original.csv> >> <final.csv>"

It's a little wordy, but very customisable and very flexible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM