Jump to content
Mr. BUGRA UGUR YAZICI

Executing python script in a feature definition

Recommended Posts

Hi,

 

I would like to know whether it is possible to execute python script directly within a feature definition.

I don't want to use software connector option because python script should be executed in an if-else statement. If the condition doesn't meet the requirements, python script will not be executed.

 

 

Thank you very much in advance.

 

 

 

 

Share this post


Link to post
Share on other sites

Hi,

 

Yes, you can use a FProcess to run anything from within a feature definition, here is an example snippet:

string exe(resolveEnv("$BINDIR") + "../../myScript")

string os(resolveEnv("$OS"))

if (os.contains("Windows"))
  exe.append(".exe")
endif

process myTool(exe)

myTool.setWorkingDir(getDesignDir())
myTool.setArguments(["-i", getDesignDir()+"/control.dat", "-o", "log.out"])
myTool.run()

Hope this helps,

Joerg

Share this post


Link to post
Share on other sites

Dear Joerg,

 

Thank you very much for your answer.

Just to speed up the process for newbies like me :

string exe("c:/Python27/python")

string os(resolveEnv("$OS"))

if (os.contains("Windows"))
  exe.append(".exe")
endif

process myTool(exe)

myTool.setArguments(["<pathofpythonscript>", "arg1"])
myTool.run()

Share this post


Link to post
Share on other sites

Hi again,

 

I realized something about FProcess issue. When I pass arguments in the feature definition, output file has no newlines and args aren't written on the file.

 

The output file that is created within the FProcess and passing arguments as it is written with the above instructions:

VCB :8.4946106VCB :8.8417073VCB :9.2119383VCB :8.4946106

The output file that is created with same arguments within a .bat file:

VCB :8.4946106
VCB :8.8417073
VCB :9.2119383
VCB :8.4946106
['C:\\Users\\bugur\\Desktop\\CAESES_Thesis\\Msc_Thesis_Setup\\GM_table.py', 'deneme']

Revised feature:

//string exe("c:/Python27/python")

//string os(resolveEnv("$OS"))

//if (os.contains("Windows"))
  //exe.append(".exe")
//endif

//process myTool(exe)

//myTool.setArguments(["C:\Users\bugur\Desktop\CAESES_Thesis\Msc_Thesis_Setup\GM_table.py", "deneme"])
//myTool.run()

string exe("../../pit.bat")
process myTool(exe)
myTool.run()

Inside .bat file :

c:\python27\python.exe C:\Users\bugur\Desktop\CAESES_Thesis\Msc_Thesis_Setup\GM_table.py deneme %*

I just wonder why there is a difference between executing .bat file and .py file in the feature definition.

Thank you very much for your time and understanding.

Share this post


Link to post
Share on other sites

I am not sure what happens here. There should not be a difference from a technical point of view in CAESES. 

 

Does it work now for you with this workaround?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...