我使用了搜索引擎。我找不到我想要的东西,而且我在编程方面也不太好。我有一个使用hashlib和M2Crypto的.py脚本,当我使用铁蟒从c#运行程序时,它说即没有模块命名为hashlib。我找不到将hashlib导入到c#或ironpython的方法,即使我搜索了所有的网络,我也尝试了下面的代码,但它似乎并不工作。请你帮忙,谢谢。从C启动python脚本的方法#
Process p = new Process(); // create process (i.e., the python program
GetShortPathName(decdbpath, shortPath, shortPath.Capacity);
GetShortPathName(db, shortPath2, shortPath2.Capacity);
p.StartInfo.FileName = "C:\\Python27\\python.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.Arguments = a+"\\pycode.py" + shortPath + " " +
txt_entermail.Text + " >" + db;
p.Start(); // start the process (the python program)
p.WaitForExit();
MessageBox.Show("Decryption Done");
终于让我找到了问题,路径PY脚本中包含空格,我解决了问题,但现在python脚本是拒绝接受的参数?感谢
string format = string.Format(shortPath + "\\pycode.py"+" "+shortPath2.ToString() + " " + txt_entermail.Text + " > " + shortPath3.ToString());
这是结果:
使用C:\用户\ WIN7 \齐亚德\ MOBILE〜1 \ DBEXPL〜1 \ WINDOW〜1 \ BIN \调试\ pycode.py参数1参数2>参数3
此线程是否对您有帮助? http://stackoverflow.com/questions/11779143/run-a-python-script-from-c-sharp –
我看到它,它没有帮助:( –
我注意到,p.StartInfo.RedirectStandardOutput = true;没有设置为true。你尝试过吗? –