Click here to Skip to main content
15,922,325 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi Guys

I am trying to open the python compiler from my c# app and compile a script. After the the code below executes it just shows the python compiler opening up , but its blank. What could be wrong??
string str = "python.exe";
Process process = new Process();
process.StartInfo.FileName = str;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = false;
process.Start();
System.IO.StreamWriter SW = process.StandardInput;
SW.WriteLine("import py_compile\r\n");
SW.WriteLine("py_compile.compile( \"IMAP2.PY\" )\r\n");
Posted
Updated 20-Nov-10 5:45am
v2

It is possible that your python compiler does not read from standard input. Test it: create a script file containing your two commands, run a command shell, and pipe your script into it by typing "python <MyScriptFile". If it works, at least you know it does read from stdin!
If it doesn't, then you may be on your own... Can you not provide this info via command line arguments?
 
Share this answer
 
Comments
sach262 20-Nov-10 12:13pm    
Thanks for the reply

do you mean open the python.exe compiler myself, and type my commands in? If so , I have done this.
sach262 20-Nov-10 18:52pm    
thanks, i got it working now. just battling now to send the compiled file to my modem over the serial port..
Try setting process.StartInfo.RedirectStandardOutput = false; to true and try again.
 
Share this answer
 
v2
Comments
sach262 20-Nov-10 12:10pm    
Hey Abhinav

I tried your suggestion , still does not work :(
sach262 20-Nov-10 18:51pm    
ok i got it working now, thanks, had to make it true and then also close the file afterwards
Abhinav S 20-Nov-10 23:02pm    
Glad it worked. Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900