I want another python script that I run on the main python script to run in a separate window. I found out that if I use start script.py from cmd, the script runs in a separate window, not in current terminal. So, I want to run the same from a python script, but there is no path to start.exe in sys.path. So where is this file located so I can add it to sys.path so that I can run scripts this way? Or can I run scripts in a separate window in other better ways?
Since start command is built in, to run it outside of cmd, including python scripts, we can use cmd /c start script.py. This works for me.
Related
I'm trying to make an automator application to run a python script so I can double click the icon and start the script.
it doesn't give me an error but it does nothing.
#!/bin/bash
echo Running Script
python /Desktop/test.py
echo Script ended
I also tried with a Shell script .sh with the same code.
it was working before with the .sh until I updated to Mac OS Ventura.
I also installed anaconda and python, but not sure how to point to anaconda environment.
any help would be great
Thank you
A shell of Automator has different PATH, setopt, and other values from your shell in terminal. Therefore the script in your Automator won't work exactly the same in your shell.
To make it work, you need to use an absolute path of the python command.
Run this command in your terminal to get the absolute path.
which python
After, fix python in your script with the previous result.
#!/bin/bash
echo Running Script
/Absolute/path/somewhere/python /Desktop/test.py
echo Script ended
To debug with showing a window of the script result
Add "Run Applescript" in your automator app with the code below.
It's not perfect but useful.
Also, in your picture, you can see the result by click the Results button.
on run {input, parameters}
display dialog input as text
end run
Can I run a script or a .exe file every time the command prompt is executed from various methods?
like maybe through Run or the toolbar in Explorer or anywhere.
I want to run a script and show something in the command prompt as an output.
If you are asking to run Python script/code on cmd then run this code:
import py_compile
py_compile.compile(filename.py,output_name.pyc)
This will create a .pyc file which you can then run in cmd using command:
python output_name.pyc
note: filename and output_name are both strings that should include fileextensions and you can write any name here.
I have opened Anaconda - then i maneuvered to the directory where a certain python program i want to run actually lies.
I then tried the %run command.
But the command does not seem to work!
So how am i to run that program?
Does anyone know the right command that one has to use in the black colored Anaconda console command line, to run a Python program existing in a certain directory (to which the command line has been taken to)
%run is a command that's run from inside of IPython. To use it, you should start ipython first. Or just run python program.py (if your program is named program.py).
I want to, from a python script, open a new terminal window.
Then, on that new window, run another python script, located on the same directory.
I needs to be on another window, because both scripts have while True loops, and I need them to run simultaneously.
How would I do that?
Thanks everyone!
You can just spawn an xterm with the python code used:
xterm -e "python /path/to/your/file.py"
This will close when the process ends.
If you need to, you can do this from inside a python script using the subprocess module (https://docs.python.org/2/library/subprocess.html).
I have a python script which I can run from pythonwin on which I give the arguments.
Is it possible to automate this so that when I just click on the *.py file, I don't see the script and it asks for the path in a dos window?
You're running on Windows, so you need an association between .py files and some binary to run them. Have a look at this post.
When you run "assoc .py", do you get Python.File? When you run "ftype Python.File", what do you get? If "ftype Python.File" points at some python.exe, your python script should run without any prompting.
Rename it to *.pyw to hide the console on execution in Windows.
You can also wrap it in a batch file, containing:
c:\path to python.exe c:\path to file.py
You can then also easily set an icon, run in window/run hidden etc on the batch file.
how does your script ask for or get its parameters? If it expects them from the call to the script (i.e. in sys.argv) and Pythonwin just notices that and prompts you for them (I think Pyscripter does something similar) you can either run it from a CMD window (commandline) where you can give the arguments as in
python myscript.py argument-1 argument-2
or modify your script to ask for the arguments itself instead (using a gui like Tkinter if you don't want to run from commandline).