2

I'm calling an iron python script from c# using

        ScriptRuntimeSetup setup = Python.CreateRuntimeSetup(null);
        ScriptRuntime runtime = new ScriptRuntime(setup);
        ScriptEngine engine = Python.GetEngine(runtime);

        ScriptSource source = engine.CreateScriptSourceFromFile("C:/KitGenerator/KitGenerator/LoadKitsFromDatabase.py");
        ScriptScope scope = engine.CreateScope();
        source.Execute(scope);

This works fine and using print outs i've proven that the code runs correctly. However inside the iron python script is a call to another python script

os.system("ipython C:\KitGenerator\Kit-Generator\GenerateKitImages.py")

(i have tried it with just (ipython "GenerateKitImages.py")

THE ISSUE: When i run the first iron python script using Ipy.exe both run perfectly fine and do as expected. HOWEVER when i run the first iron python script using the c# script engine it only runs the first script and the second script is never called.

i'm lost on this one. I can confirm it is nothing to do with : permissions, dependencies.

a gold medal and pizza for the man who can fix this problem.

Jack Dalton
  • 3,536
  • 5
  • 23
  • 40

1 Answers1

2

First, the os.system call should use a raw (r"") string:

os.system(r"ipython C:\KitGenerator\Kit-Generator\GenerateKitImages.py")

Otherwise the backslashes will cause issues.

However, since you said it works from ipy.exe, my guess is that ipython is on your PATH in the first case and not the second case. You can set the PATH environment variable from C#, include the complete path to ipython in the os.system call, or ensure that the PATH is set before calling the C# program, by changing it globally.

Community
  • 1
  • 1
Jeff Hardy
  • 7,632
  • 24
  • 24