Python Forum
Open windows cmd prompt and run cmds with python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Open windows cmd prompt and run cmds with python
#3
(Jul-13-2022, 07:51 AM)Gribouillis Wrote: Not a Windows user here, but you could try
import subprocess as sp
process = sp.Popen(['cmd', '/k', 'node serveronly'], cwd='C:/MagicMirror')
process.wait()

Great, Thanks.

It runs the command, but it stops running my current python script to execute the MagicMirror cmd.

Is there a way to open a whole new cmd prompt window and execute that chunk of code there, that way my main python script doesn't get interrupted and I can still use it in the background.

Here's what I mean:
This is what I get when I run it. I have my Voice Assistant run, and when I open MagicMirror it stops running because it runs the cmd in the same window, not a new one.
Output:
┌──────────────────────────────────────────────────── B.A.X.T.E.R ────────────────────────────────────────────────────┐ │ Listening... │ └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ ┌──────────────────────────────────────────────────── B.A.X.T.E.R ────────────────────────────────────────────────────┐ │ Recognizing... │ └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ ┌───────────────────────────────────────────────────── Commander ─────────────────────────────────────────────────────┐ │ hello │ └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ ┌──────────────────────────────────────────────────── B.A.X.T.E.R ────────────────────────────────────────────────────┐ │ Hello, how are you today? │ └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ ┌──────────────────────────────────────────────────── B.A.X.T.E.R ────────────────────────────────────────────────────┐ │ Listening... │ └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ ┌──────────────────────────────────────────────────── B.A.X.T.E.R ────────────────────────────────────────────────────┐ │ Recognizing... │ └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ ┌───────────────────────────────────────────────────── Commander ─────────────────────────────────────────────────────┐ │ magic mirror │ └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ [13.07.2022 20:47.16.529] [LOG] Starting MagicMirror: v2.18.0 [13.07.2022 20:47.16.530] [LOG] Loading config ... [13.07.2022 20:47.16.532] [LOG] Loading module helpers ... [13.07.2022 20:47.16.532] [LOG] No helper found for module: alert. [13.07.2022 20:47.16.535] [LOG] Initializing new module helper ... [13.07.2022 20:47.16.536] [LOG] Module helper loaded: updatenotification [13.07.2022 20:47.16.536] [LOG] No helper found for module: clock. [13.07.2022 20:47.16.573] [LOG] Initializing new module helper ... [13.07.2022 20:47.16.574] [LOG] Module helper loaded: calendar [13.07.2022 20:47.16.574] [LOG] No helper found for module: compliments. [13.07.2022 20:47.16.574] [LOG] No helper found for module: weather. [13.07.2022 20:47.16.580] [LOG] Initializing new module helper ... [13.07.2022 20:47.16.580] [LOG] Module helper loaded: newsfeed [13.07.2022 20:47.16.580] [LOG] All module helpers loaded. [13.07.2022 20:47.16.610] [LOG] Starting server on port 8080 ... [13.07.2022 20:47.16.618] [LOG] Server started ... [13.07.2022 20:47.16.618] [LOG] Connecting socket for: updatenotification [13.07.2022 20:47.16.619] [LOG] Starting module helper: updatenotification [13.07.2022 20:47.16.620] [LOG] Connecting socket for: calendar [13.07.2022 20:47.16.620] [LOG] Starting node helper for: calendar [13.07.2022 20:47.16.620] [LOG] Connecting socket for: newsfeed [13.07.2022 20:47.16.620] [LOG] Starting node helper for: newsfeed [13.07.2022 20:47.16.620] [LOG] Sockets connected & modules started ... [13.07.2022 20:47.16.621] [LOG] Ready to go! Please point your browser to: http://localhost:8080
Thanks.
Reply


Messages In This Thread
RE: Open windows cmd prompt and run cmds with python - by Extra - Jul-14-2022, 12:45 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  'pip' not recogmnized in windows prompt MaartenRo 1 521 Dec-21-2023, 09:05 AM
Last Post: menator01
  [SOLVED] [Windows] Right way to prompt for directory? Winfried 4 2,228 Jan-17-2023, 09:28 PM
Last Post: markoberk
  Windows install does not create .exe, shortcut,etc to open hammer 4 2,154 May-05-2022, 12:33 PM
Last Post: hammer
  Is it possible to open windows and do screenshots with Python? cubangt 2 1,453 Jan-14-2022, 03:57 PM
Last Post: cubangt
  Running Python in Command Prompt Anwar 3 3,277 Nov-15-2020, 03:15 PM
Last Post: snippsat
  starting python from windows command prompt MaartenRo 4 3,001 Sep-04-2020, 12:25 PM
Last Post: MaartenRo
  Open windows media player minimised TamP 1 2,349 Aug-02-2020, 08:40 PM
Last Post: Larz60+
  Python's id() function output in prompt and script mode stormshadow 4 3,948 Dec-10-2018, 10:08 AM
Last Post: stormshadow
  Subprocess command prompt (Windows) arnaur 6 10,702 Sep-06-2018, 07:22 AM
Last Post: arnaur
  Problem with interactive python prompt Groot_04 4 3,274 Aug-02-2018, 08:39 AM
Last Post: Groot_04

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020