I am trying to run a python script from a c# console application. This c# code works fine until I import our custom python module that in turn imports other modules, e.g. arcpy, keyring, etc within the python script. The script runs fine from the cmd line but once in c# it just hangs. In the end, a system deadlock error pops up. How do I get my python to run? The goal is to get the password from python to c#. I am open to other approaches...
c#
private static string getPassword(string database)
{
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = @"C:\Python27\ArcGIS10.6\python.exe";
string script = @"C:\src\xxxx\etw_password.py";
start.Arguments = $"\"{script}\" \"{database}\"";
start.UseShellExecute = false;
start.CreateNoWindow = false;
start.RedirectStandardOutput = true;
start.RedirectStandardError = true;
string errors;
string password;
Console.WriteLine(start.Arguments);
using(Process process = Process.Start(start))
{
errors = process.StandardError.ReadToEnd();
password = process.StandardOutput.ReadToEnd();
}
return password;
}
python: not working-- I replaced our custom python security calls with "x"
import sys
import xxxx
database = sys.argv[1]
password = xxxx.xxxx(database, 'xxxx')
print password
python: this works fine
import sys
database = sys.argv[1]
print database
I also run the test below to check if it was just our module or if the problem extended to others. I tested with numpy and arcpy. Both failed.
python: not working
import sys
import numpy
database = sys.argv[1]
print database