Subprocess.wait() in Python 2.7 vz Pthon 3.x - python-3.x

I'm just migrating my script from Python27 to Python 394 to run my build process like this:
p = subprocess.Popen(_make_clean, creationflags = subprocess.CREATE_NEW_CONSOLE)
p.wait()
p = subprocess.Popen(_make_rebuild, creationflags = subprocess.CREATE_NEW_CONSOLE)
p.wait()
Was working pretty nice in Python 27 but now I can see in Python 394 the Python script is not waiting for subprocesses. Of course, here it is necessary to wait until the first one (clean) is finished to start the second one (rebuild). I was able to make it work without the flag 'CREATE_NEW_CONSOLE'. Unfortunately, I need to separate the outputs for users to see what is the progress. It is just a mess if all scripts are running in the same console.
Why it is not working any more?

Ok, this is an interesting finding. I'm using ConEmu as my main terminal and it is fully integrated into Windows. In the past, I was NOT running my scripts over this emulated terminal and that seems to be the reason why I have this issue today. ConEmu is opening a new terminal window for each subprocess but in a different way than the native Windows Command-Line. When the script is called over Windows CMD everything is fine.

Related

How to check if a script is already running

How do you check if your script is already running to prevent it from running/opening multiple times.
I am aiming for it to either quit and allow the script to open again or stop the new one from running.
Using:
Python 3.8
Windows 10
File type .pyw
Ide: Thonny
I have looked and haven't been able to find a answer.

Popen doesn't run my exe

(Python 3)
I'm trying to use popen in a little script to run an executable
The executable is at :
https://github.com/Gorov/FCM_nips_workshop
I'm on windows and by modifying a little the github README command I can run easily the program using
RE_FCT ../data/SemEval.train.fea.sst ../data/SemEval.test.fea.sst predict.fea.fullnerpair.onlyne.txt ../data/vectors.nyt2011.cbow.semeval.filtered 5 0.005
The exe is RE_FCT and all the following text is just arguments
So using a terminal it works just fine and display informations while runing
But when I try to make it run using my little python script, it does nothing. Actually something seems runing but it never ends and doesn't display anything
Here's my code
import subprocess
command = ['RE_FCT', '../data/SemEval.train.fea.sst', '../data/SemEval.test.fea.sst ', 'predict.fea.fullnerpair.onlyne.txt', '../data/vectors.nyt2011.cbow.semeval.filtered', '5', '0.005']
process = subprocess.Popen(test, cwd="fcm", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process.wait()
print() #sometimes it helps
Note that I'm already running another exe with similar code and it works
Thanks in advance
Just solved it
I don't know exactly what is going on but the problem is with the process.wait(), I just deleted it and replaced the Popen function with the run fonction and it works
The difference between those two is that popen allows the script to run immediatly after you call it by creating a process, while using run you have to wait for the task to end

Infinite loading in Jenkins when slaves are upgraded to Python 3

Our team has upgraded our slaves (Windows) from Python 2 to 3. When we try to run our Jenkins jobs, automated test cases were run successfully but we were stuck in xUnitIgnoredTests.py when this part is executing. Infinite loading is encountered when running the job.
enter image description here
We have upgraded our python file with Python 3 syntax. Is there any setup that might be missing?
Thanks.
RDP/connect to an agent and run the command directly. You might be able to get better console output that way.
If you still have Python2 on them run the script with that interpreter too to ensure that something else hasn't changed on the agent that is affecting the script.

Python - execute sequential commands in same windows command prompt

I am very new to Python (been learning for a few days) . Can anyone help me with the following issue please?
I am trying to write a program to automate the testing of built in commands of a product which is installed on windows and linux.
Before any of the commands can run, the profile needs to be set using profile.cmd.
The commands ( command1.cmd, command2.cmd etc) then need to run in the same windows command prompt as profile.cmd as they rely on the environment which this sets.
The problem I find is that after profile.cmd has been run, python closes the windows command prompt and opens a new one for command1.cmd.
command1.cmd therefore fails to run properly as it is in a new command prompt which has not had the environment set by profile.cmd.
My code is shown below. I am currently testing on windows but will also need to test on linux.
Any suggestions would be much appreciated. Thanks - Kevin
import subprocess
rc = subprocess.run (["profile.cmd"],stdout=subprocess.PIPE)
print(rc.stdout.decode("ascii"))
rc = subprocess.run (["command1.cmd"],stdout=subprocess.PIPE)
print(rc.stdout.decode("ascii"))
rc = subprocess.run (["command2.cmd"],stdout=subprocess.PIPE)
print(rc.stdout.decode("ascii"))
rc = subprocess.run (["command3.cmd"],stdout=subprocess.PIPE)
print(rc.stdout.decode("ascii"))

Using script to automatically start program when the system boot up (linux, shell)

Here is the situation, I'm planning to use a simple script to start a program call "STAF", when the Suse system is fully booted. I have achieved this by putting it in the "/etc/init.d/", but this script is basically executed at the background, which means that I cannot see its progress.
When the "STAF" is started this way it works but it doesn't show any working progress when its running service (for example ping, or system backup), instead if I start the "STAF" manually by running the same script whit a terminal, the working progress of "STAF" can be seen on the terminal. Its sort of like the program needs to be started with a interactive terminal, but how can I make this starting process automatic and it should imitate human opening a terminal and run the script?
Sorry if I explained it poorly because its a confusing situation. Thanks.
First, go to the KDE Startup and Shutdown options under System Settings. Then add this command as a new startup script:
konsole -e bash nameofyourscript.sh
I believe the screen utility can do what you describe. Instead of running STAF on startup, you would run screen STAF. To open that terminal, you would run screen -ls to get the screen ID, and screen -r ... to open it.
(Disclaimer: I have not tried this.)

Resources