I'm trying to execute the detect.py file using C# by creating a new process and passing ProcessStartInfo
Here is my method
Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo
{
FileName = @"C:\Users\malsa\anaconda3\python.exe",
RedirectStandardInput = true,
RedirectStandardError = true,
CreateNoWindow = false,
UseShellExecute = false
};
p.StartInfo = info;
p.Start();
using (StreamWriter sw = p.StandardInput)
{
if (sw.BaseStream.CanWrite)
{
sw.WriteLine(string.Format("cd {0}", @"C:\Users\malsa\Desktop\Yolo"));
sw.WriteLine(string.Format("detect.py --source {0}", ImagePath));
}
}
p.WaitForExit();
For now the arguments should be passed to cmd, but since am setting the file to python.exe the arguments should be written in python.
As shown in the image this how we can execute the detect.py by giving the --source ImgFile.jpg in cmd. The problem is that how can I execute the detect.py in Python-Shell by giving arguments such as ImgFile.jpg so that I can write these arguments in C# ?
I have tried something such as
subprocess.call(['C:\Users\malsa\Desktop\Yolo\detect.py', 0])
but I couldn't get it work.