Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

start python application from c# code

hello every one
i am new in c# , i made python application and it compiled correctly ,
however i want to start this python application from c# code using(Process.Start("");)
but it doesn't work!
how to run this python application from c# code
please not that the application is compiled ,
i want to run the application (not the code)
So maybe show us some code and an error? Process.Start should work?
Is this useful for you...?

Quote:public string run_cmd(string cmd, string args)
{
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = "PATH_TO_PYTHON_EXE";
start.Arguments = string.Format("\"{0}\" \"{1}\"", cmd, args);
start.UseShellExecute = false;// Do not use OS shell
start.CreateNoWindow = true; // We don't need new window
start.RedirectStandardOutput = true;// Any output, generated by application will be redirected back
start.RedirectStandardError = true; // Any error in standard output will be redirected back (for example exceptions)
using (Process process = Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
string stderr = process.StandardError.ReadToEnd(); // Here are the exceptions from our Python script
string result = reader.ReadToEnd(); // Here is the result of StdOut(for example: print "test")
return result;
}
}
}
BTC - bc1q3efew3yzfwhdz290dafykaw0a2w56g2j69g2c6
ETH - 0xf1c873217032468990D3313da6509D1b813c4671
USDT - 0xf1c873217032468990D3313da6509D1b813c4671
PP - [email protected]
(Jun 11, 2020 09:06 AM)Shadow_Cloud Wrote:  So maybe show us some code and an _error_?  Process.Start should work?
there wasnot any error
if i double click to python application , it runs correctly
if i use process.start(c# code) it dosont run
Try this code:
Quote:       string fileName = @"C:\your_script_name.py";

           Process p = new Process();
           p.StartInfo = new ProcessStartInfo(@"C:\Python27\python.exe", fileName) // full path to python path + script
           {
               RedirectStandardOutput = true,
               UseShellExecute = false,
               CreateNoWindow = true
           };
           p.Start();

           string output = p.StandardOutput.ReadToEnd();
           p.WaitForExit();

           Console.WriteLine(output);
Does your python already in executable format or still in .py extension??
(Jun 11, 2020 04:55 PM)Accord Wrote:  Does your python already in executable format or still in .py extension??
in executable format
make new process and add your python application agreements


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Bass_ReevesAug 20, 2023 01:44 AM 9 631 Aug 20, 2023 01:44 AM
Last Post: Lucky4L
[C#] by opsecJun 17, 2022 02:11 PM 2 227 Jun 17, 2022 02:11 PM
Last Post: benio2
[Python] by mikehackMay 9, 2022 11:12 AM 2 151 May 9, 2022 11:12 AM
Last Post: mikehack