executing perl script using python - python-3.x

i have a perl script 'ProcessServerData.pl' in 'C:\Users\Gurpreet Singh\Desktop\Amar_AG\KA03MM7155' and wish to run it through python program present in 'C:\Users\Gurpreet Singh\Desktop\Amar_AG'. What should my python program be?

Related

How to force line buffering for python 3.6.7?

I use "stdbuf -oL" to force line buffering when running commands on Ubuntu. This works for Python 2.7, but does not seem to work for Python 3.6.7:
# test_buf.py
import time
for i in range(10):
print('a')
time.sleep(1)
I run the command: stdbuf -oL python test_buf.py > output.txt
When running with Python 3.6.7 the file output.txt updated only after the interpreter exists. When running with Python 2.7 output.txt is updated with every line written.
1. Any idea why stdbuf does not work with Python 3.6.7?
2. Any other alternative to force line buffering (not from within the Python process)?

python3: How can I run a python script when python starts?

I have a shortcut which runs python3 in a terminal window. I would like to add some import commands to a python script which is to be run when python starts.
How can I do this?
eg; I have xfce4-terminal -e python3 which starts a graphical terminal session with python3 running. I want to add something to this to make python3 execute a script, however I do not want python to exit at the end of the script, which is the default behaviour if a filename is given immediatly following the python3 command.
See python --help. It mentions an environment variable called PYTHONSTARTUP which looks like it could help you get where you want.

How to run python script with arguments in python 3 interpreter?

I am using PyZo(with python3.5) and dont know how to run a script with arguments from PyZo's python interpreter - or from python interpreter in general. I found following working example here for python3 but dont know how to pass arguments (e.g. csv file input_data.csv) to the script
>>> exec(open("./script.py").read())
This is working in iPython:
In [1]: run script.py input_data.csv
What is the python 3 equivalent of the iPython command above ?
Thanks
Note 1
When running a script with arguments from an OS command line you type this:
$ python script.py input_data.csv
What I would expect when using python interpreter is being able to run a python script e.g. like this:
>>> script.py input_data.csv
i.e. without calling python executable, or using 'exec(open("./script.py").read())', etc.
For me running a script with arguments is very fundamental thing to do but apparently not for majority of users.
>>> import subprocess
>>> subprocess.run('python script.py input_data.csv', shell=True)

Running a bash job within a python script

I was hoping for some advice on using the subprocess module.
I'm trying to run a bash job within a python script so my bash command (in the right directory) is: ./program myjob.inp
This is just running the executable "program" with myjob.inp being the input file (and my python script constantly updates myjob.inp).
I know that if I just wanted to run "program", I could do something like:
with open("tmp.dat","w") as fstore_tmp:
subprocess.call(["./program"], stdout = fstore_tmp)
However, I can't figure out how to run the job taking in the input file myjob.inp such that it's doing the equivalent of ./program myjob.inp. I tried:
with open("tmp.dat","w") as fstore_tmp:
subprocess.call(["./program", "myjob.inp"], stdout = fstore_tmp)
However, that doesn't seem to be working. Does anyone have any suggestions? Thanks!

how to run a python script as soon as another process ends

there is a process running that will write some output to a set of files. I wrote a python script that will make a copy of these output files in another directory. Right now I can simply run the python script when I notice the other process is done. How can I get this script to be run automatically when the other process is done?
I don't have control over the other process's source code. Messing with the source code might make the results file inadmissible, so I'd rather not touch it at all.
I am running Python 2.7.1 in an Ubuntu 11.x machine.
You don't tell much about what is the program running before the Python script, but if it is or you can convert to a shell script, you can use this syntax:
$ first-script.sh && python-script.sh
The && operator means that if the first script finished successfully, run the second afterwards.
Of course, you could invoke the python interpreter with your script directly as the 2nd script. Here I assume that it is wrapped in a Bash script.

Resources