Python script with executeStreamCommand in Apache Nifi ? Import not found - apache-nifi

I try to use ExecuteStreamCommand processor in Apache Nifi in order to execute a simple Python Script.
Here is the python script:
import pandas as pd
import sys
file = pd.read_json(sys.stdin)
file.to_json(sys.stdout)
Here is the processor configuration:
I have the error:
I don't know where I am wrong.

Here’s what you can do: Add the full path to the Python command in the Command Argument space, and provide the full path to the script under command arguments. This will work.

Related

Checking for a running python process using python

I have a python script called speech.pyw. I don't want it showing up on the screen when run so I used that extension.
How can I check using another python script whether or not this script is running? If it isn't running, this script should launch it.
Off the top of my head, there are at least two ways to do this:
You could make the script create an empty file in a specific location, and the other script could check for that. Note that you might have to manually remove the file if the script exits uncleanly.
You could list all running processes, and check if the first one is among those processes. This is somewhat more brittle and platform-dependant.
An alternative hybrid strategy would be for the script to create the specific file and write it's PID (process id) to it. The runner script could read that file, and if the specified PID either wasn't running or was not the script, it could delete the file. This is also somewhat platform-dependant.
!/usr/bin/env python2
import psutil
import sys
processName="wastetime.py"
def check_if_script_is_running(script_name):
script_name_lower = script_name.lower()
for proc in psutil.process_iter():
try:
for element in proc.cmdline():
if element.lower() == script_name_lower:
return True
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
return False;
print(check_if_script_is_running(processName))
sys.stdin.readline()

How to call connect() method of weblogic in python which is called inside a shell script?

The requirement is to call the weblogic function:
connect([username, password], [url], [adminServerName])
inside a python file which is again called inside a shellscript as follows:
Inside shell script:
python myweblogiccall.py
I am getting an exception like
unknown name connect
when called inside the python file
Although WLST scripts have py or jy extension they are different than Python scripts in the way they function. Any WLST script needs an environment to be setup before coming up into action. There are 2 ways you can run your WLST scripts. I am assuming that you only need help to run WLST and a working WLST script is handy already.
Source setDomainEnv.sh and call WLST script as below.
source <Domain_HOME>/bin/setDomainEnv.sh
java weblogic.WLST <Script_HOME>/script.py
Run the WLST script through wlst.sh
./<Oracle_HOME>/Oracle_common/bin/wlst.sh <Script_HOME>/script.py

How to exceute bash script from pyspark

I have huge number of csv files which I am processing via bash.
Is there a way that i can call the bash script file from pyspark and then generate a RDD out of that?
Used subprocess.call to trigger the bash code.
subprocess.call("run.bash", shell=True)

executing functions from windows console - python

I have implemented some logic through python functions and am looking for a way to calling those functions more efficiently. Is there a way to calling these functions from windows command prompt or python cmd like below?
python function:
def logic1(args)
...
want to call the function like this:
logic1(args)
Import the file in the python console like this:
from my_file.py import *
Or
from my_file.py import name1, name2 ...
Now you can use these in the python console. Out is just the same as importing into files.
For calling the functions in the Windows prompt you need to separate each function into its own file and use py2exe to convert them into executables. This may be an overhead of work though, depending on what you want to achieve.

Is there the redirect operator >> in Python 3?

I did not know there was a redirect operator in Python 2, for example here somebody is using it to redirect something to a file. I just knew that there is one in Bash. Is still there such a thing in Python 3?
print function in Python 3.x optionally accept file parameter, you can specify file object.
import sys
print(n, file=sys.stderr)
Using the shell redirection this way
python foo_bar.py > file
is still possible with python 3.x as this is not a feature of python itself but this is actually a feature of the shell interpreter in which the python command is run.

Resources