Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Invoke-Command fails to run command when used with Start-Process

$
0
0

I have a PowerShell test framework which works like this: 

1. I have several test scripts. Within each script I use Invoke-Expression to call various commands/executable-binaries. I also ensure that I print the command I am invoking... 

	[string] $cmd = "mybinary.exe -s" 
	$out = run-cmd "$cmd"
	$cmd = "devcon find pci*"
	$out = run-cmd "$cmd"

	function run-cmd ([string] $cmd){
		Write-Output "CMD: $cmd"
		$output = Invoke-Expression "$cmd 2>&1"
		Write-Output "OUT: $output"
		return $output
	}

2. I have test suites, which is nothing but a simple text file. Each line in test-suite file indicates the script to be executed: 

	Script1.ps1 
	Script2.ps1 
	...
	ScriptN.ps1 



3. I use a script which reads the suite file and uses Start-Process to call the scripts mentioned in the above test-suite file, one after the other.

Problem- The issue with this approach is that, it is not very consistent. Sometime I see commands in "$cmd" variable to be executed with correct output:

CMD: mybinary.exe -s 
OUT: version 4.5.3.2
This is expected output of mybinary.exe with -s optionCMD: devcon find pci*
OUT: PCI\VEN_15AD&DEV_0405&SUBSYS_040515AD&REV_00\3&18D45AA6&0&78: VMware SVGA 3D
PCI\VEN_15AD&DEV_07A0&SUBSYS_07A015AD&REV_01\3&18D45AA6&0&AD: PCI Express standard Root Port
PCI\VEN_15AD&DEV_07A0&SUBSYS_07A015AD&REV_01\3&18D45AA6&0&B5: PCI Express standard Root Port
PCI\VEN_15AD&DEV_07A0&SUBSYS_07A015AD&REV_01\3&18D45AA6&0&BD: PCI Express standard Root Port
PCI\VEN_15AD&DEV_07A0&SUBSYS_07A015AD&REV_01\3&18D45AA6&0&C5: PCI Express standard Root Port
PCI\VEN_8086&DEV_7191&SUBSYS_00000000&REV_01\3&18D45AA6&0&08: PCI standard PCI-to-PCI bridge
PCI\VEN_15AD&DEV_0740&SUBSYS_074015AD&REV_10\3&18D45AA6&0&3F: VMware VMCI Bus Device
PCI\VEN_15AD&DEV_07A0&SUBSYS_07A015AD&REV_01\3&18D45AA6&0&AE: PCI Express standard Root Port
PCI\VEN_15AD&DEV_07A0&SUBSYS_07A015AD&REV_01\3&18D45AA6&0&B6: PCI Express standard Root Port
PCI\VEN_15AD&DEV_07A0&SUBSYS_07A015AD&REV_01\3&18D45AA6&0&BE: PCI Express standard Root Port



 Other times, I see the command being printed, but I do not see any output of the command, 

CMD: mybinary.exe -s CMD: devcon find pci*

From my experiements I think that in this case when command does not give any output, it seems like Inovke command does not execute the command at-all, but only prints it. Again remember that I am starting these scripts using start-process so I cannot use tools like PowerGUI to debug such issue.

Does anyone know how I can debug such scenarios ? Or why this happens when the command is not executed?



-Pranav





Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>