On Windows, the python subprocess command to open a cmd window is simply:
import subprocess
subprocess.Popen('cmd.exe')
Can anyone tell me what the command to open the cmd equivalent in Linux is?
I'm going to be copying some python code from my Windows machine to my Raspberry Pi and am new to Linux - I know that this line of code won't open the terminal on a Linux OS the same way it will on Windows.
Thanks in advance!
Replace cmd.exe with gnome-terminal in order to open a terminal on Linux
Different distros use different terminal programs. xterm should work on just about everything, so you could Popen('xterm') and then require the people figure out how to get xterm on their system if its not there by default.
Related
Using Python 3.10:
import os
os.system('notepad.exe')
Notepad launches, but if I try that with pythonw.exe Idle doesn't launch but the exit code is also 0.
Not sure why. Is it because pythonw is not an external application? How can I launch IDLE from the interpreter?
I apologize, not sure how to include code properly....
Many thanks
pythonw is not IDLE. pythonw is just another copy of python that is marked as a Windows GUI application, so it doesn't attach to your terminal session. IDLE is a separate command. Depending on where your Python installation is, you can run:
C:\Python310\Lib\idlelib\idle.bat
Or, even easier:
pythonw -m idlelib
I am using atom editor. I installed atom runner for run to my programs but i have encountered too many problems. I want to run pyfiles in cmd console automaticly. How can i do this
In a nutshell:
How can i run py files in cmd console with shortcut
I am using windows
This is honestly not related to stack overflow since this isn't exactly a computer programming question. More of an operating system question. However, I believe you can install bash (linux command line) on windows and this would help solve your problem. Here is a link:
https://www.windowscentral.com/how-install-bash-shell-command-line-windows-10
OR if you prefer using the windows command line, this link can explain how to run python (although i'd recommend using bash and not cmd):
http://www.cs.bu.edu/courses/cs108/guides/runpython.html
I suggest you install the "Script" extension and then run Atom using cmnd-I in the editor. Your file runs in the terminal.
I was helping a fellow Stack Overflow-er today and I noticed that I don't know what terminal IDLE uses in Windows. I am tacitly assuming that Python didn't write their own terminal for Windows, and that they probably use an API that gives them some version of cmd or powershell. I verified that the interpreter runs on cmd, but I don't know about IDLE.
What terminal does IDLE use in Windows?
IDLE is not built on an external shell or terminal, but on the Tkinter GUI toolkit.
The source code to the editor window can be read here; for the interactive shell, see here.
I have cygwin installed on my win 7 pc. When I'm running the python shell, I get the OS name as posix (which is expected) and many DOS commands don't work using os.system("DOS command").
Is there a way I can avoid entering the posix shell from Windows command prompt?
You need to run the native Windows Python interpreter rather than the Cygwin port.
Assuming you already have both installed on your system, check your PATH setting to confirm the native Windows edition comes first.
If this doesn't work for you, and you'd RATHER run the Cygwin port, then you are going to have to avoid os.system() calls, and instead switch to using the new subprocess package. Give a read over http://docs.python.org/library/subprocess.html
I'm making Python software using wx GUI library but was wondering how to run this script on different OS's. For example, do I need to create executable installation file or bat file on Windows and sh file in Ubuntu?
I've got #!/usr/bin/env python at the top of the file and I can seem to run it by actually double clicking it and clicking it on "RUN" on prompt window but I would like it to be more professional as the users are not programmers.
Being used to run python scripts on both linux and Windows environments, I know that you can use the same script for both environments.
Keep using your shebang in Linux, it won't be procesed in windows (as it is actually a comment :).
Once Python is installed in Windows, you can actually simply double click on the script (it will run by default in a cmd window), run it using the cmd or launch it in idle.
If you want to develop python scripts on windows however, you'll need some more tools :).
If you want to be more professional (and prevent your users to modify the code :), you can still think about creating an exe file : http://www.lyxia.org/blog/developpement/python/creez-des-executables-46
(warning, french inside), by using pyinstaller http://www.pyinstaller.org/ . Works for windows and linux