@@ -8,7 +8,7 @@ namespace CSSimpleFunctions
88{
99 public class PyCS
1010 {
11- bool console = true , exist1 = false , exist2 = false , exist3 = false , RunDone = false ;
11+ bool console = true , exist1 = false , exist2 = false , exist3 = false ;
1212
1313 void AllowTLS12 ( )
1414 {
@@ -210,19 +210,33 @@ public void InstallPip()
210210 }
211211 }
212212
213- public bool IsRunDone ( )
213+ public void Pip ( string [ ] args )
214214 {
215- return RunDone ;
215+ ProcessStartInfo run0 = new ProcessStartInfo ( ) ;
216+ run0 . FileName = "python3_12\\ Scripts\\ pip.exe" ;
217+ run0 . Arguments = "install " + string . Join ( " " , args ) ;
218+ run0 . UseShellExecute = false ;
219+ run0 . RedirectStandardOutput = true ;
220+ using ( Process process = Process . Start ( run0 ) )
221+ {
222+ using ( StreamReader reader = process . StandardOutput )
223+ {
224+ string result = reader . ReadToEnd ( ) ;
225+ if ( console )
226+ {
227+ Console . WriteLine ( result ) ;
228+ }
229+ }
230+ }
216231 }
217232
218- public void Pip ( string [ ] args )
233+ public void PipUpgrade ( string [ ] args )
219234 {
220235 ProcessStartInfo run0 = new ProcessStartInfo ( ) ;
221236 run0 . FileName = "python3_12\\ Scripts\\ pip.exe" ;
222- run0 . Arguments = "install " + string . Join ( " " , args ) ;
237+ run0 . Arguments = "install --upgrade " + string . Join ( " " , args ) ;
223238 run0 . UseShellExecute = false ;
224239 run0 . RedirectStandardOutput = true ;
225- run0 . CreateNoWindow = true ;
226240 using ( Process process = Process . Start ( run0 ) )
227241 {
228242 using ( StreamReader reader = process . StandardOutput )
@@ -243,7 +257,6 @@ public void PipLocal(string[] args)
243257 run0 . Arguments = "install " + string . Join ( " " , args ) + " --no-index --find-links /" ;
244258 run0 . UseShellExecute = false ;
245259 run0 . RedirectStandardOutput = true ;
246- run0 . CreateNoWindow = true ;
247260 using ( Process process = Process . Start ( run0 ) )
248261 {
249262 using ( StreamReader reader = process . StandardOutput )
@@ -259,10 +272,6 @@ public void PipLocal(string[] args)
259272
260273 public void Run ( string script )
261274 {
262- if ( RunDone )
263- {
264- RunDone = false ;
265- }
266275 File . Create ( "python3_12\\ main.py" ) . Close ( ) ;
267276 File . WriteAllText ( "python3_12\\ main.py" , script ) ;
268277
@@ -271,130 +280,35 @@ public void Run(string script)
271280 run0 . Arguments = "python3_12\\ main.py" ;
272281 run0 . UseShellExecute = false ;
273282 run0 . RedirectStandardOutput = true ;
274- run0 . CreateNoWindow = true ;
275283 using ( Process process = Process . Start ( run0 ) )
276284 {
277285 using ( StreamReader reader = process . StandardOutput )
278286 {
279287 string result = reader . ReadToEnd ( ) ;
280288 Console . WriteLine ( result ) ;
281- RunDone = true ;
282289 }
283290 }
284291 }
285292
286- //public void Run(string script, bool showConsole)
287- //{
288- // if (RunDone)
289- // {
290- // RunDone = false;
291- // }
292- // File.Create("python3_12\\main.py").Close();
293- // File.WriteAllText("python3_12\\main.py", script);
294-
295- // ProcessStartInfo run0 = new ProcessStartInfo();
296- // run0.FileName = "python3_12\\python.exe";
297- // run0.Arguments = "python3_12\\main.py";
298- // run0.UseShellExecute = false;
299- // if (!showConsole)
300- // {
301- // run0.RedirectStandardOutput = true;
302- // run0.CreateNoWindow = true;
303- // using (Process process = Process.Start(run0))
304- // {
305- // using (StreamReader reader = process.StandardOutput)
306- // {
307- // string result = reader.ReadToEnd();
308- // Console.WriteLine(result);
309- // RunDone = true;
310- // }
311- // }
312- // }
313- // else
314- // {
315- // run0.RedirectStandardOutput = false;
316- // run0.CreateNoWindow = false;
317- // using (Process process = Process.Start(run0))
318- // {
319- // using (StreamReader reader = process.StandardOutput)
320- // {
321- // string result = reader.ReadToEnd();
322- // Console.WriteLine(result);
323- // RunDone = true;
324- // }
325- // }
326- // }
327- //}
328-
329293 public void RunFile ( string filePath )
330294 {
331- if ( RunDone )
332- {
333- RunDone = false ;
334- }
335295 ProcessStartInfo run0 = new ProcessStartInfo ( ) ;
336296 run0 . FileName = "python3_12\\ python.exe" ;
337297 run0 . Arguments = filePath ;
338298 run0 . UseShellExecute = false ;
339299 run0 . RedirectStandardOutput = true ;
340- run0 . CreateNoWindow = true ;
341300 using ( Process process = Process . Start ( run0 ) )
342301 {
343302 using ( StreamReader reader = process . StandardOutput )
344303 {
345304 string result = reader . ReadToEnd ( ) ;
346305 Console . WriteLine ( result ) ;
347- RunDone = true ;
348306 }
349307 }
350308 }
351309
352- //public void RunFile(string filePath, bool showConsole)
353- //{
354- // if (RunDone)
355- // {
356- // RunDone = false;
357- // }
358- // ProcessStartInfo run0 = new ProcessStartInfo();
359- // run0.FileName = "python3_12\\python.exe";
360- // run0.Arguments = filePath;
361- // run0.UseShellExecute = false;
362- // if (!showConsole)
363- // {
364- // run0.RedirectStandardOutput = true;
365- // run0.CreateNoWindow = true;
366- // using (Process process = Process.Start(run0))
367- // {
368- // using (StreamReader reader = process.StandardOutput)
369- // {
370- // string result = reader.ReadToEnd();
371- // Console.WriteLine(result);
372- // RunDone = true;
373- // }
374- // }
375- // }
376- // else
377- // {
378- // run0.RedirectStandardOutput = false;
379- // run0.CreateNoWindow = false;
380- // using (Process process = Process.Start(run0))
381- // {
382- // using (StreamReader reader = process.StandardOutput)
383- // {
384- // string result = reader.ReadToEnd();
385- // Console.WriteLine(result);
386- // RunDone = true;
387- // }
388- // }
389- // }
390- //}
391-
392310 public string GetOutput ( string script )
393311 {
394- if ( RunDone )
395- {
396- RunDone = false ;
397- }
398312 File . Create ( "python3_12\\ main.py" ) . Close ( ) ;
399313 File . WriteAllText ( "python3_12\\ main.py" , script ) ;
400314
@@ -403,36 +317,28 @@ public string GetOutput(string script)
403317 run0 . Arguments = "python3_12\\ main.py" ;
404318 run0 . UseShellExecute = false ;
405319 run0 . RedirectStandardOutput = true ;
406- run0 . CreateNoWindow = true ;
407320 using ( Process process = Process . Start ( run0 ) )
408321 {
409322 using ( StreamReader reader = process . StandardOutput )
410323 {
411324 string result = reader . ReadToEnd ( ) ;
412- RunDone = true ;
413325 return result ;
414326 }
415327 }
416328 }
417329
418330 public string GetFileOutput ( string filePath )
419331 {
420- if ( RunDone )
421- {
422- RunDone = false ;
423- }
424332 ProcessStartInfo run0 = new ProcessStartInfo ( ) ;
425333 run0 . FileName = "python3_12\\ python.exe" ;
426334 run0 . Arguments = filePath ;
427335 run0 . UseShellExecute = false ;
428336 run0 . RedirectStandardOutput = true ;
429- run0 . CreateNoWindow = true ;
430337 using ( Process process = Process . Start ( run0 ) )
431338 {
432339 using ( StreamReader reader = process . StandardOutput )
433340 {
434341 string result = reader . ReadToEnd ( ) ;
435- RunDone = true ;
436342 return result ;
437343 }
438344 }
0 commit comments