nrofis
nrofis

Reputation: 9796

PowerShell verbose Start-Process command

I have a PowerShell script that starts a process:

$pythodDir, $argsOriginalList = $args

$pythonExePath = Join-Path $pythodDir "python.exe"
$argsList = @("--no-render") + $argsOriginalList
Start-Process -FilePath $pythonExePath -ArgumentList $argsList

I wish to see the full command line of the Start-Process for example:

C:\python\python.exe --no-render --arg1 value

I didn't find a flag to render the full command that Start-Process creates. Is there any way to verbose it?

Upvotes: 1

Views: 1162

Answers (1)

Cpt.Whale
Cpt.Whale

Reputation: 5351

You can get the command line by grabbing two properties from the ProcessInfo of the process you started:

# Capture the process object using -PassThru
$p = Start-Process -FilePath $pythonExePath -ArgumentList $argsList -PassThru

# Output the command line
($p.StartInfo.FileName,$p.StartInfo.Arguments) -join ' '

For example:

$p = Start-Process -FilePath 'Notepad.exe' -ArgumentList 'c:\folder\file.txt' -PassThru
($p.StartInfo.FileName,$p.StartInfo.Arguments) -join ' '

C:\WINDOWS\system32\notepad.exe C:\folder\file.txt

Upvotes: 2

Related Questions