1

This is a common question that most people asked already. I go through the lot of documentation that written on different topics how to integrate Python and C#. But most of them are too difficult and can not apply with my requirements.

I have a main program that written on Visual Studio and C#. Also I have another program written in normal Python. I want to run that python script parallely with the C# program. Can anyone tell me how can I perform this task.

3
  • what is your intention? what do you want to achieve? Commented Jun 13, 2017 at 11:28
  • I want to run the Python script after some C# script. Commented Jun 13, 2017 at 11:30
  • You may execute the python script at the end of your c# script? Process.Start(...). If you can describe your problem more precisely, it would be easier to help you. Commented Jun 13, 2017 at 11:47

1 Answer 1

1

Try calling Python from IronPython in Visual Studio, you can use it to call Python's native functions, classes, types, methods and it'll compile directly to bytecode. Also, since you have your native functions supported, you will be able to import modules and dependencies as well.

Also, there is

System.Diagnostics.Process.Start("CMD.exe", "python script.py");

Where script.py is your python script and it'll get executed from the cmd, the main difference is that IronPython will compile directly inside your C# script and the second method will run cmd where you'll need to have Python locally installed in order to run the script you're calling.

Sign up to request clarification or add additional context in comments.

4 Comments

If he just wants to execute two separate scripts, IronPython seems to be a bit too much.
I just assumed he had already tried System.Diagnostics.Process.Start("CMD.exe", "python ./script.py"); and he wanted to write both scripts in the same file.
Yes I want to write both scripts in same C# file
I editted my answer for you, @ChathurikaJayawardana . The first part tells you how to write both scripts in the same file, the second one is a simpler way to execute both files parallely.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.