Python Forum
multi-line CMD in one-line python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
multi-line CMD in one-line python
#1
hi, sorry for my bad English,
i tried to combine this multi-line (exclude the Import) into one-line,
import os
os.system("title installing numpy")
os.system("pip install numpy")
os.system("timeout 10")
but after hours google, because I did not find a proper keyword,
I cannot find the answer,

maybe any user in here can help, thank you
Reply
#2
What is the purpose of combining this into one line? Also why call timeout 10? If you want to stop the python program during 10 seconds, it can be done this way
import time
time.sleep(10)
Reply
#3
the purpose is making GUI program using that install the missing "packages" in a new window,
lets said the user needs "packages" called NumPy that are not installed,
then the program will open a new cmd window showing the package being install,
instead "not responding" Tkinter window GUI
(usually, users will kill this process or think this program is not professional)

the timeout is just an additional code to make the program longer, it is not necessary,
I just need to know is that python can run multiple cmd commands in 1-line or not

anyway thanks for the reply
Reply
#4
(Jan-01-2022, 09:10 AM)kucingkembar Wrote: he purpose is making GUI program using that install the missing "packages" in a new window,
lets said the user needs "packages" called NumPy that are not installed,
then the program will open a new cmd window showing the package being install,
instead "not responding" Tkinter window GUI
(usually, users will kill this process or think this program is not professional)
In general should make packages included when install with pip.
So then it's done in setup.py with install_requires .
Then all is done with pip install my_pacakge.

There can be serval problems that can occurs if try to this for users after install.
Also should not use os.system(unsafe) as subprocces has taken over that task.
Should capture output so know what going on,did it work(error message) or eg is is it already installed.
import subprocess

output = subprocess.run('pip install numpy', capture_output=True, encoding='utf-8')
print(output.stdout)
Output:
Requirement already satisfied: numpy in c:\python39\lib\site-packages (1.20.2)
Reply
#5
thank you snippsat for the reply,

maybe the wrong on my side, I forget to mention: the script is in pyw extension, so there is no "print" that will show up

and back to my main question, is there any way to combine multiple line cmd code into 1-line,
using subprocess.run or os.system
Reply
#6
after googling for a long time I found the answer by accident
you just need to combine the codes and separate between code with the "&" symbol
import os
os.system("title installing numpy & pip install numpy & timeout 10")
thank you who answer
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question [SOLVED] [Beautiful Soup] Move line to top in HTML head? Winfried 0 160 Apr-13-2025, 05:50 AM
Last Post: Winfried
  Βad Input on line 12 Azdaghost 4 942 Mar-25-2025, 02:40 PM
Last Post: deanhystad
  Insert command line in script lif 4 912 Mar-24-2025, 10:30 PM
Last Post: lif
  Entry field random pull from list, each return own line Bear1981 6 742 Feb-25-2025, 06:09 AM
Last Post: Pedroski55
  How to revert back to a previous line from user input Sharkenn64u 2 872 Dec-28-2024, 08:02 AM
Last Post: Pedroski55
  Pandas - error when running Pycharm, but works on cmd line zxcv101 2 2,391 Sep-09-2024, 08:03 AM
Last Post: pinkang
  Simplest way to run external command line app with parameters? Winfried 2 1,197 Aug-19-2024, 03:11 PM
Last Post: snippsat
  Printing the code line number arbiel 6 1,599 Jun-30-2024, 08:01 AM
Last Post: arbiel
  How to add multi-line comment section? Winfried 2 1,324 Jun-04-2024, 07:24 AM
Last Post: Gribouillis
Information Is it possible to multi line a Basic Function Construct line statement? If so how? BrandonKastning 7 1,842 May-23-2024, 03:02 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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