简体   繁体   中英

C# PowerShell running non PowerShell scripts

I am trying to run a tcl script in a powershell so that I can take advantage of some of the powershell features, namely, the tee feature to display the script output in the console and record it to a file in realtime in Windows.

The issue is that I need to call the tcl interpreter ( tclsh ) and provide it the tcl script "C:\\myScript.tcl" with arguments --arg1 arg1 --arg2 arg2 ...

So the command that I can run in a cmd process is of the form:

tclsh "C:\myScript.tcl" --arg1 arg1 --arg2 arg2

I have tried creating a new process and starting the powershell, something like:

System.Diagnostics.ProcessStartInfo procStartInfo =
                new System.Diagnostics.ProcessStartInfo("powershell", command);

where command is tclsh "C:\\myScript.tcl" --arg1 arg1 --arg2 arg2

or

System.Diagnostics.ProcessStartInfo procStartInfo =
                new System.Diagnostics.ProcessStartInfo("cmd", command);

where command is /k powershell.exe tclsh "C:\\myScript.tcl" --arg1 arg1 --arg2 arg2

but those dont work. I either get tclsh.exe : Parameter -command is specified already. or it just doesnt run anything.

What would be the best way to accomplish this? Ideally, I would like to be able to execute this:

tclsh "C:\myScript.tcl" --arg1 arg1 --arg2 arg2 | tee "C:\myOutFile.txt"

and am open to other suggestions. I am aware of windows utilities that can be downloaded and installed to perform the tee function, but I do not want to have to install any third party tools to do this.

Ideas??

Thanks!

Running

powershell "&{ tclsh --arg1 arg1 --arg2 arg2 | Tee-Object C:\myoutfile.txt }"

should work, apart from that you usually don't have write permissions on C:\\ .

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