-3
I am developing a C#project, which uses python scripts as an engine (I did not use Ironpython due to its limitations, I work with pandas), what I do is simply run the script through a PROCESS in c#, passing which python.exe directory and which script directory I want to run, EXAMPLE:
private void ExecutarScript()
{
this.bnt_ExecutarScript.Enabled = false;
string p_cmd = @"C:\Users\dalton.takeuchi\Anaconda3\python.exe";
string file = @"C:\PROJETO 11\Python\VMN\VMN.py";
run_script(p_cmd, file);
this.CarregarGridSimulacao();
this.bnt_ExecutarScript.Enabled = true;
}
private void run_script(string p_cmd, string file)
{
if (processoEmExecucao == false)
{
try
{
processoEmExecucao = true;
p_cmd = string.Format(@"'{0}'", p_cmd).Replace("'", "\"");
file = string.Format(@"'{0}'", file).Replace("'", "\"");
ProcessStartInfo start = new ProcessStartInfo(p_cmd, file);
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
start.CreateNoWindow = true;
using (Process process = Process.Start(start))
{
process.WaitForExit();
/*
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
//MessageBox.Show(result," PYTHON]:",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
*/
}
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
finally
{
processoEmExecucao = false;
}
}
}
The problem is that I cannot leave these directories, both python and scripts as something fixed on the system, so they will give problem on other machines...
Could you tell me how to configure the directories for each installation in a non-manual way? I thought of using a txt to store the directories and read straight from it... it is easy to edit a txt and would end the problem, but I’m having difficulties with it too. I need to know the txt directory so I can read and edit it...
From now on, thank you!
See my comment in your original question.
– Leandro Angelo
Possible duplicate of FILES IN PYTHON C# + DIRECTORIES
– Leandro Angelo