Skip to content

Commit 2a2100e

Browse files
Added function to check if PyCS run is done
1 parent d6c1550 commit 2a2100e

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

PyCS.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace CSSimpleFunctions
88
{
99
public class PyCS
1010
{
11-
bool console = true, exist1 = false, exist2 = false, exist3 = false;
11+
bool console = true, exist1 = false, exist2 = false, exist3 = false, RunDone = false;
1212

1313
void AllowTLS12()
1414
{
@@ -373,6 +373,11 @@ public PyCS(bool console)
373373
}
374374
}
375375

376+
public bool IsRunDone()
377+
{
378+
return RunDone;
379+
}
380+
376381
public void Pip(string[] args)
377382
{
378383
ProcessStartInfo run0 = new ProcessStartInfo();
@@ -396,6 +401,10 @@ public void Pip(string[] args)
396401

397402
public void Run(string script)
398403
{
404+
if (RunDone)
405+
{
406+
RunDone = false;
407+
}
399408
File.Create("python3_12\\main.py").Close();
400409
File.WriteAllText("python3_12\\main.py", script);
401410

@@ -411,12 +420,17 @@ public void Run(string script)
411420
{
412421
string result = reader.ReadToEnd();
413422
Console.WriteLine(result);
423+
RunDone = true;
414424
}
415425
}
416426
}
417427

418428
public void Run(string script, bool showConsole)
419429
{
430+
if (RunDone)
431+
{
432+
RunDone = false;
433+
}
420434
File.Create("python3_12\\main.py").Close();
421435
File.WriteAllText("python3_12\\main.py", script);
422436

@@ -434,13 +448,18 @@ public void Run(string script, bool showConsole)
434448
{
435449
string result = reader.ReadToEnd();
436450
Console.WriteLine(result);
451+
RunDone = true;
437452
}
438453
}
439454
}
440455
}
441456

442457
public void RunFile(string filePath)
443458
{
459+
if (RunDone)
460+
{
461+
RunDone = false;
462+
}
444463
ProcessStartInfo run0 = new ProcessStartInfo();
445464
run0.FileName = "python3_12\\python.exe";
446465
run0.Arguments = filePath;
@@ -453,12 +472,17 @@ public void RunFile(string filePath)
453472
{
454473
string result = reader.ReadToEnd();
455474
Console.WriteLine(result);
475+
RunDone = true;
456476
}
457477
}
458478
}
459479

460480
public void RunFile(string filePath, bool showConsole)
461481
{
482+
if (RunDone)
483+
{
484+
RunDone = false;
485+
}
462486
ProcessStartInfo run0 = new ProcessStartInfo();
463487
run0.FileName = "python3_12\\python.exe";
464488
run0.Arguments = filePath;
@@ -473,13 +497,18 @@ public void RunFile(string filePath, bool showConsole)
473497
{
474498
string result = reader.ReadToEnd();
475499
Console.WriteLine(result);
500+
RunDone = true;
476501
}
477502
}
478503
}
479504
}
480505

481506
public string GetOutput(string script)
482507
{
508+
if (RunDone)
509+
{
510+
RunDone = false;
511+
}
483512
File.Create("python3_12\\main.py").Close();
484513
File.WriteAllText("python3_12\\main.py", script);
485514

@@ -494,13 +523,18 @@ public string GetOutput(string script)
494523
using (StreamReader reader = process.StandardOutput)
495524
{
496525
string result = reader.ReadToEnd();
526+
RunDone = true;
497527
return result;
498528
}
499529
}
500530
}
501531

502532
public string GetFileOutput(string filePath)
503533
{
534+
if (RunDone)
535+
{
536+
RunDone = false;
537+
}
504538
ProcessStartInfo run0 = new ProcessStartInfo();
505539
run0.FileName = "python3_12\\python.exe";
506540
run0.Arguments = filePath;
@@ -512,6 +546,7 @@ public string GetFileOutput(string filePath)
512546
using (StreamReader reader = process.StandardOutput)
513547
{
514548
string result = reader.ReadToEnd();
549+
RunDone = true;
515550
return result;
516551
}
517552
}

0 commit comments

Comments
 (0)