Different environment variables on git bash and windows cmd - python

I have a python file in which I'm using the subprocess module to execute some command line scripts.
I'm using Git bash to run this python file. In the file, I execute the script:
KG_URL=http://127.0.0.1:8900
This script sets the variable successfully when I run it manually on the git bash command line.
But when I execute this using the python file, it gives me the following error:
'KG_URL' is not recognized as an internal or external command,operable program or batch file.
I tried digging deeper into this and I found out that executing the python file on git bash is the equivalent of running those scripts on the Windows cmd. When I tried running the set command without parameters (to get the current environment variables) on the Windows cmd, I found out that the variable KG_URL does not exist. But when I ran the same command on git bash, I can see that KG_URL exists.
Any idea why this discrepancy exists? And how can I solve this issue?
The reason why I'm executing these scripts in a Python file is because I need to convert it into an exe later. Assuming that all environments where I run this exe will have git bash installed, is there any way of ensuring that these scripts run only through git bash, and not the Windows cmd?

Related

Run command right before launch in VSCode

I'm trying to run a remote ssh debugging session in Visual Studio Code. The only problem is the destination system, which is NixOS and i'd like to run a command nix-shell -p python38Full before launching the project.
I know about tasks, I've tried configuring them, but it runs in different terminal, which isn't helpful, because the command above creates shell for executing python environment.
Can I add a line to Python's launch command or execute a command right before launching?

Windows Jenkins "Windows Batch Command" vs Command Prompt

We are using jenkins to run a python script through command prompt. The command is like C:\Program Files\...\someapp.bat test.py. The someapp.bat is a customized python and it has a library called arcpy. The test.py file includes a statement import arcpy.
This command works fine on command prompt on the machine. However, when running through Jenkins, it complains arcpy does not exist. Then I used ssh to access the machine and ran the same command. It has the same error. Then I compared the path in the two command prompts (on machine and ssh), the environments has only one difference which is the Windows. One under user folder and the other under system. But it does not seem to be a dependency of the python bat.
So, in general, what's difference between a remote command line window and a local command line window if logged in as the same user? Any clue is helpful!

Running a python script through a windows batch file using ExecuteStreamCommand NIFI

I understand that this question may have been repeated many times before - I am new to Nifi and unfortunately none of the previous answers worked for me.
I am trying to run a simple python script using the ExecuteStreamCommand processor (in Windows 10). However, I cannot call the python script directly from Nifi as it requires the conda environment to be activated (it gives me an import error for python packages- the same happens when the script is called from both nifi and command prompt).
I have since written a basic batch script to activate the conda environment and run the python script (see below).
activate.bat
CALL conda activate base
python sample.py
CALL conda deactivate
This works well and produces the output I need when run from the command line. However, calling the bat file from Nifi does not seem to do anything. It does not generate an error (simply pass the incoming flowfile to output with the working directory added to each line of the incoming csv file).
The config in Nifi:
Command Arguments: C:\Temp\activate.bat
Command Path: C:\Windows\System32\cmd.exe
Any help would be greatly appreciated.
This worked for me!
cmd "/c activate [my_env] && python my_script.py && deactivate"
Source: Conda environments and .BAT files
Still not sure what the underlying issue was ....

I'm learning how to use Vagrant and I was trying to run a python script

On GitBash I ran
vagrant up
vagrant ssh
Python abc.py
It gave an error
/usr/bin/env: ‘python\r’: No such file or directory
I have tried dos2unix command it didn't work
python version:
Python 2.7.12+
How can I get past this error message?
Make sure your %USERPROFILE%\.bashrc adds python path to your PATH
export PATH=/c/path/to/Python:$PATH
Then launch your bash again, and see if the error persists.
If the vagrant ssh uses a different bash resource file, type (in the same bash "vagrant ssh" session)
echo export PATH=/c/path/to/Python:\$PATH >> ~/.bashrc
source ~/.bashrc
Then try again Python abc.py
‘python\r’:
You've got screwed up line endings in your python script. Has nothing to do with vagrant, but what you used to write your code.
Open up vim in your ssh session and fix the line endings

using python 2.7 for windows executing an sh file

Windows 10.1 installed
python 2.7 installed
I have an application package that has a file named install.sh and the read me states to run the install.sh file. I have tried numerous times to execute the .sh file without success. I get a name error and that install is not defined. What is the proper syntax to execute the .sh file as directed in my read me?
You need to have a Bash shell installed to run .sh files. Easy options include Git Bash and Cygwin.

Categories

Resources