I'm developing a C # project, which uses python scripts as the engine (I did not use IronPython because of its limitations, I work with pandas), what I do is simply execute the script through a PROCESS in C #, passing the python.exe directory and which directory of the script 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 can not leave these directories, both python and scripts as something fixed on the system, so that they will give trouble on other machines ...
Could you give me a way to configure the directories for each installation in a way that is not manual? I thought of using a txt to store the directories and read it straight ... it's easy to edit a txt and it would end the problem, but I'm having difficulty with that as well. I need to know the txt directory so you can read and edit it ...
Thanks in advance!