simple function I thought I would share:

Ive been running quite a few python scripts using EXEC, so I thought it might be nice to have a function to execute these scripts.

function saved as python:

$ReturnVar = print(exec('[$$PythonExePath]','[$$PythonLibPath]\\[$PythonFunction].py [$PythonArgument]',8));
return(substr($ReturnVar,10,990));

substitution vars:
$$PythonExePath
$$PythonLibPath

input Vars:
$PythonFunction
$PythonArgument

local var:
$ReturnVar

python script: (saved as test.py)

from sys import argv
lstArgs = argv[1:]
print '||'.join(lstArgs)

to execute the python script: (GlobalVar = $TestVar)
$TestVar = python(‘test’,’“go cubs” “another argument”’);


The python script is pretty simple, but takes an argument, and the print returns a string value. What happens in the script is pretty open ended.

Im not sure what this would do on a per-record basis in a dataflow, but used in a script this should be pretty harmless.
[edit] if you run this per record, you’re going to spam STDOUT with the print return values per function call. So that could be a bad idea. You can remove the print from the function… but running per-record, it still runs very very slow.


jlynn73 :us: (BOB member since 2009-10-27)

In my Linux environment i am able to run python program at command prompt that requires a input parameter successfully.

But when invoking the same program through BODS script its failing with below error


57310	4146984736	PRINTFN	10/17/2018 2:50:16 PM	1:   File "<string>", line 1     /root/user/program.py PARA=2018     ^ SyntaxError: invalid syntax

I ran the below command in BODS Script


print(exec('/usr/bin/python','-c "/root/user/prgram.py [$GV_PARA]"',8));

Any suggestion?


Farha (BOB member since 2014-03-05)

run your expression at the command line and don’t use double quotes unless you really need them.

unless you have spaces in your file path, or have spaces in a single argument … misuse of double quotes will easily waste countless hours of your life.


jlynn73 :us: (BOB member since 2009-10-27)