Home > Blockchain >  PowerShell verbose Start-Process command
PowerShell verbose Start-Process command

Time:03-16

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?

CodePudding user response:

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
  • Related