Dj_Dad0
Dj_Dad0

Reputation: 21

Execute a python file c#

I have a python converter that works calling it with some parameters from cmd. I want to create an exe that automatically calls it with the needed parameters, which are the model I want to convert and the name of the model that it will be created. The code is:

blender -b -P dae-obj.py -- file.dae file.obj

Upvotes: 0

Views: 102

Answers (3)

Arko Chakraborti
Arko Chakraborti

Reputation: 423

Have you tried using IronPython? I see you wish to use C# along with python. In case your primary application is in C# and you wish to leverage some of the features of python, you can use IronPython to create an environment where a python code can be executed and it can interact with the C# application as well. I hope this link will be able to solve some of the problems. They have explained it well with code

Upvotes: 1

OldGeeksGuide
OldGeeksGuide

Reputation: 2918

I believe you want the subprocess module - https://docs.python.org/3/library/subprocess.html

One way to do what I think you're trying to do would be:

import subprocess

out = subprocess.getoutput('blender -b -P dae-obj.py -- file.dae file.obj')

Though I expect you don't care about the output. You could also try getstatusoutput or call

Upvotes: 0

jegtugado
jegtugado

Reputation: 5141

Here is a sample code in order to launch a command prompt. Adjust it to your needs.

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; // Hides the cmd
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "blender -b -P dae-obj.py -- file.dae file.obj"; // Parameters
process.StartInfo = startInfo;
process.Start();

Upvotes: 0

Related Questions