0

Edited* Solution: Remove "pause". I'm running a python script which calls upon powershell to execute a line of code:

def download():
    subprocess.call('C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe yt-dlp https://www.youtube.com/watch?v=jtjnnykvnh4;pause', shell=True)

download()

The problem was that after executing, it would output "Press Enter to continue..." This interrupts the program.*in my original example I forgot to include the ";pause" which is what turned out to be what was causing the interruption in the program, as kindly pointed out by the marked answer. Below is the fixed line of code which does not prompt "press enter to continue" after running:

def download():
    subprocess.call('C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe yt-dlp https://www.youtube.com/watch?v=jtjnnykvnh4;kill $pid', shell=True)

download()

Apologies for confusion caused by the original post. Thanks for the help.

2
  • 1
    What exactly is yt-dlp in your case? Is it a shell script that specifically requires Powershell? Can you read and understand the script, in that case? Is it creating the pause? Commented Jan 7, 2022 at 0:56
  • @KarlKnechtel it's an open source program if im not wrong. Commented Jan 7, 2022 at 1:01

1 Answer 1

1

PowerShell normally exits unless you specify -NoExit at the commandline. Even then it will not include the message you are seeing unless you add a pause at the end instead. Even so, I would expect your command to look more like

'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe & {yt-dlp https://www.youtube.com/watch?v=jtjnnykvnh4}'

My guess this has more to do with Python, though I have not encountered it before...have you tried executing the PowerShell line from another commandline (cmd on Windows or bash on Linux/Mac or another favourite) to verify that you get the same result independently of Python?

Another possibility is that it is the yt-dlp tool that you are using that has the pause effect (I am not familiar with the tool). Is it a PowerShell module? Or is it something that can be run on the commandline and you don't need PowerShell as a middleman anyway? Would it have a "silent" or "-q" argument, or another more relevant argument?

Sign up to request clarification or add additional context in comments.

1 Comment

Good points, but note the following: There's no reason to use "& { ... }" in order to invoke code passed to PowerShell's CLI via the (implied in Windows PowerShell) -command (-c) parameter - just use "..." directly. Older versions of the CLI documentation erroneously suggested that & { ... } is required, but this has since been corrected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.