Python not getting invoked by Powershell - python-3.x

I am working on some automation where a python script need to be executed by a PowerShell script.
If I execute the python from the PowerShell (e.g., ISE), it all works fine. In the actual flow, the PowerShell function is first executed by the Application which uses this PowerShell script, which in turn must invoke the python script being called in that PowerShell function.
However, every time App executes this PowerShell, the python is not being invoked at all.
The Environment variables are also set properly.
Not sure where to look for errors. Any leads ?
I am simply calling the python script as:
py "C:\Program Files\<some location>\script.py" $arg1 $arg2

which error you are getting?
can you elaborate more?
have you tried with "python" instead

My bad. I guess i should have done a bit more troubleshooting. The issue was because of a Python module which was not installed for all user (including the one which application uses to invoke the script). Once installed, it works fine.

Related

Why does cmd and powershell recognize "python" but not "py"?

I seem to be having the opposite issue as this user in this question. I can run python successfully, but py does not work for me. Overall, this is not a big deal but when I try to run code in VS Code, I get the error below:
py: The term 'py' is not recognized as a name of a cmdlet, function, script file, or executable program.
How can I either make VScode run python or change my system to accept py?
When I first downloaded Python, it was not placed into the path but I was able to fix that. I also confirmed that VS Code has selected the correct interpreter for Python in the same place.
EDIT: IMAGES
Path directory
Path used in enviroment
When you write "python" on CMD or Powershell, it checks the given keyword("python" here) in all the directories in Environment Variables.
In the case of python, the directory mentioned for python in Environment Variables > Path, you will find "python.exe" and not "py.exe".
So your cmd or PowerShell recognizes python and not py.

Monit not invoking python script <--> OS is CentOS

Monit not invoking python script <--> OS is CentOS. first line in python script is "#!/usr/bin/env python3" when i tried to invoke python script from my terminal its working but monit is not able to trigger the script.
I tried to call python script from shell script in monit but no luck. even i tried adding PATH variable as second line to shell script.
any help will be appreciated.
Issue is with PATH environmental variable, like cron, monit is only taking subset of values from PATH variable instead of all values. So after explictly adding $PATH variable after shell interpreter, issue got resolved

Execute python executable and script inlucing full path

Im trying to create a python script with executes a series of python and sql scripts.
Some need to be executed using one python executable and some using another.
I've tried
from subprocess import call
call([r"C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\pythonw.exe", r"C:\Path\to\python\file\blabla.py"])
And
call([r"cd C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3", "pythonw.exe", r"C:\Path\to\python\file\blabla.py"])
But the script isnt being executed.
I think the problem might be "How to execute an .exe file in windows terminal including full path to it"?
Please check my code. It is working well in my side.
from subprocess import call
call([r"C:\Python38\python.exe", r"E:\python\hello.py"])
As i think, the problem is that you use pythonw.exe.
if you use pythonw.exe, you can see any log in terminal.
Pythonw is useful for running script with GUI.

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"))

IZPack Setting Linux Environment Variables

I am sure this has to be out there somewhere, but after about a day of searching I am stuck. I am trying to use IZPack to do an installation on Linux and trying to call a shell script that sets some environment variables. However I don't know how to "source" the script instead of just running it. Running the script using:
<executable type="bin" stage="postinstall" targetfile="$INSTALL_PATH/myscript.sh" os="unix"/>
This only executes the script, it does not source it. So all exports of ENV variables are lost once the script completes.
How can I source my scripts from IZPack instead of just running them?
IMHO you simply cannot influence the shell environment your Java process of your IzPack installer is running in from that process itself.
Torsten is right. This is not an issue of IzPack, Java or anything else, this is just the way operating system process work with respect to environment variables ;-)

Resources