-1

I tried executing start chrome in the command line and it worked. However when I tried the same using subprocess.Popen(), throws a file not found error.

Please find blow the code and let me know the reason for the same.

import subprocess as sp
sp.Popen(['start','chrome'])

Thank you.

Ashis Sahoo
  • 104
  • 2
  • 8
  • 1
    Try `sp.Popen(['start','chrome'], shell=True)`. –  Jun 07 '21 at 14:54
  • Does this answer your question? [Why does subprocess.Popen not work](https://stackoverflow.com/questions/7823910/why-does-subprocess-popen-not-work) – Tomerikoo Jun 07 '21 at 14:55
  • 1
    "The only time you need to specify shell=True on Windows is when the command you wish to execute is built into the shell (e.g. dir or copy). You do not need shell=True to run a batch file or console-based executable." -- [docs](https://docs.python.org/3/library/subprocess.html). `start` is a shell command. –  Jun 07 '21 at 14:59

2 Answers2

1

I can not tell you why it does not work with subprocess, but if you do not rely on it, try os:

import os
os.system("start chrome")
mnikley
  • 1,625
  • 1
  • 8
  • 21
1

You have to use shell = True in this case since start is a Windows built-in command.

import subprocess as sp
sp.Popen(['start','chrome'], shell=True)

Check Running windows shell commands with python for detail.

LaoDa581
  • 563
  • 4
  • 18