How Can I run some Python Scripts in VS C++?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Feb 20 13:12:17 EST 2009


En Fri, 20 Feb 2009 15:47:06 -0200, david <bing.liu at gmail.com> escribió:

> Basically I have some python scripts to do some document processing,
> all in command line tho.
> I want to have an C++ application so that my scripts can run in dialogs
> (API).
> I saw a post before using c# to run python scripts within the c# main.
> I am willing to run my python scripts within c++.
> Thanks.

So you want to execute a Python script, in a different process, as if you  
typed the command line?
That's not different to executing any other external program in C# - in  
fact is a C# question, no Python involved. Try something like this:

     Process p = new Process();
     p.StartInfo.FileName = "path\to\python.exe";
     p.StartInfo.Arguments = "path\to\your\script.py other arguments";
     p.Start();
     p.WaitForExit();
     p.Close()

There are other properties you may want to use, like  
RedirectStandardOutput; see the C# documentation.

-- 
Gabriel Genellina




More information about the Python-list mailing list