从C启动python脚本的方法#

2024-06-26 01:34:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我用了搜索引擎。我找不到我想要的东西,而且我不擅长编程。我有一个.py脚本,它使用hashlib和M2Crypto,当我使用iron python从c运行程序时,它说没有名为hashlib的模块。我找不到将hashlib导入c或ironpython的方法,即使我搜索了所有的网络,我尝试了以下代码,它似乎也不起作用。你能帮忙吗谢谢。在

   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脚本拒绝接受参数了吗?谢谢

^{pr2}$

结果是:

用法C:\Users\win7\Ziad\MOBILE~1\DBEXPL~1\WINDOW~1\bin\Debug\pycode.py论证1论证2>;论证3


Tags: thepy脚本dbprogramprocesshashlibcapacity
2条回答

我相信你的问题出在你的python脚本上,而不是在你的c。见Unable to import "hashlib"

试试看,告诉我:

p.Arguments = string.Format("{0} {1}", cmd, args);
     p.UseShellExecute = false;
     p.RedirectStandardOutput = true;
     using(Process process = Process.Start(p))
     {
         using(StreamReader reader = process.StandardOutput)
         {
             string result = reader.ReadToEnd();
             Console.Write(result);
         }
     }

相关问题 更多 >