Question

I used the search engine. I couldn't find the thing I want,and i'm not that good in programming.I have a .py script that use hashlib and M2Crypto,and when i use iron python to run the program from c# it says that no module named hashlib. I couldn't find a way to import hashlib to c# or ironpython even tho i searched all the net, i tried the following code it doesn't seem to work too. Can you help please thanks.

   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");

finally i found the problem, the path to the py script contained a space i fixed the problem, but now python script is refusing to take the arguments ? thanks

string format = string.Format(shortPath + "\\pycode.py"+" "+shortPath2.ToString() + " " + txt_entermail.Text + " > " + shortPath3.ToString());

this is the result:

usage C:\Users\win7\Ziad\MOBILE~1\DBEXPL~1\WINDOW~1\bin\Debug\pycode.py argument1 argument2 > argument3

Was it helpful?

Solution

Try that and tell me :

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);
         }
     }

OTHER TIPS

I believe your problem is in your python script, not in your c#. See Unable to import "hashlib"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top