2
votes

I have a powershell Script that runs fine in the ISE, but when I run it directly from the .ps1 file it stops at this point:

Write-Host "Attempting to start FFMPEG Process with arguments:$ArgumentList::::" -ForegroundColor Green
Start-Process $SCRIPT:FFMPEGLocation $ArgumentList -Wait

I get the Write-Host printout, with the correct Argument List, but no window pops up for the start-process or anything. I made sure to use the SCRIPT scope variable for anything that is outside the function. It runs fine in ISE just not when I run it in Console. No errors either, and the $SCRIPT:FFMPEGLocation variable is a direct path to the exe to be executed.

Any help would be greatly appreciated, and if you need more let me know.

PSVersion               5.1.14393.1066   
OSVersion               10.0.14393
2
Why do you think you need script scope for the path and filename of the executable? Why Start-Process? In fact, why do you need script at all? Just run the executable from the PowerShell prompt with the parameters you want. - Bill_Stewart
Thank you Bill! My current script is over 200 lines long, and I realized halfway through that I should have instead coded in C# instead, but I was rolling along too much. I have certain variables, like $SCRIPT:FFMPEGLocation declared at the top of my script outside of a try { section. I know, I was a bad boy and am trying to do too much in a scripting language. I'm just trying to make this work outside of the ISE for now, and then I can make a program or service in C# later. - Drew Courtney
Running commands works just fine from PowerShell whether in the ISE or not. You have not included nearly enough information in your question. (If I had to guess, you have a scoping problem.) - Bill_Stewart
Yes, Bill. You are correct, I have not included enough info. And it probably is a scoping problem, among many other problems that I have, which is why I was using the SCRIPT Scope for anything that wasn't declared and set in the same block. the output shows everything correct in the console which is why I am stumped with the scope. But i shall trudge along. - Drew Courtney
I recommend starting small and writing a very short script that contains only the absolute minimum amount of code needed to reproduce the problem. This is often referred to as an SSCCE. - Bill_Stewart

2 Answers

1
votes

As per comments, check the value passed to Start-Process to ensure it contains what you expect as the issue is likely to be with $SCRIPT:FFMPEGLocation.

The difference between the ISE and Console with regard to scope can be frustrating. See this SuperUser post which explains the behaviour further . You may also find this post helpful; BartekB explains that F5 in the ISE actually dot-sources the script instead of calling it, and provides a function to run a clean session.

0
votes

An alternative method which will also wait on the process that needs to be run:

& $EXE /arg 1 /arg 2 -etc 2>&1 | % { $_ }

This will execute the command and pass the args, redirect any errors to the output stream and then print that output (for some reason, I've had bad luck with actually getting output from commands)