Skip to content

Commit fcfa5a1

Browse files
update: removed broken run function for PyCS, updated README.md
1 parent 17dfd72 commit fcfa5a1

2 files changed

Lines changed: 129 additions & 81 deletions

File tree

PyCS.cs

Lines changed: 80 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -279,48 +279,48 @@ public void Run(string script)
279279
}
280280
}
281281

282-
public void Run(string script, bool showConsole)
283-
{
284-
if (RunDone)
285-
{
286-
RunDone = false;
287-
}
288-
File.Create("python3_12\\main.py").Close();
289-
File.WriteAllText("python3_12\\main.py", script);
282+
//public void Run(string script, bool showConsole)
283+
//{
284+
// if (RunDone)
285+
// {
286+
// RunDone = false;
287+
// }
288+
// File.Create("python3_12\\main.py").Close();
289+
// File.WriteAllText("python3_12\\main.py", script);
290290

291-
ProcessStartInfo run0 = new ProcessStartInfo();
292-
run0.FileName = "python3_12\\python.exe";
293-
run0.Arguments = "python3_12\\main.py";
294-
run0.UseShellExecute = false;
295-
if (!showConsole)
296-
{
297-
run0.RedirectStandardOutput = true;
298-
run0.CreateNoWindow = true;
299-
using (Process process = Process.Start(run0))
300-
{
301-
using (StreamReader reader = process.StandardOutput)
302-
{
303-
string result = reader.ReadToEnd();
304-
Console.WriteLine(result);
305-
RunDone = true;
306-
}
307-
}
308-
}
309-
else
310-
{
311-
run0.RedirectStandardOutput = false;
312-
run0.CreateNoWindow = false;
313-
using (Process process = Process.Start(run0))
314-
{
315-
using (StreamReader reader = process.StandardOutput)
316-
{
317-
string result = reader.ReadToEnd();
318-
Console.WriteLine(result);
319-
RunDone = true;
320-
}
321-
}
322-
}
323-
}
291+
// ProcessStartInfo run0 = new ProcessStartInfo();
292+
// run0.FileName = "python3_12\\python.exe";
293+
// run0.Arguments = "python3_12\\main.py";
294+
// run0.UseShellExecute = false;
295+
// if (!showConsole)
296+
// {
297+
// run0.RedirectStandardOutput = true;
298+
// run0.CreateNoWindow = true;
299+
// using (Process process = Process.Start(run0))
300+
// {
301+
// using (StreamReader reader = process.StandardOutput)
302+
// {
303+
// string result = reader.ReadToEnd();
304+
// Console.WriteLine(result);
305+
// RunDone = true;
306+
// }
307+
// }
308+
// }
309+
// else
310+
// {
311+
// run0.RedirectStandardOutput = false;
312+
// run0.CreateNoWindow = false;
313+
// using (Process process = Process.Start(run0))
314+
// {
315+
// using (StreamReader reader = process.StandardOutput)
316+
// {
317+
// string result = reader.ReadToEnd();
318+
// Console.WriteLine(result);
319+
// RunDone = true;
320+
// }
321+
// }
322+
// }
323+
//}
324324

325325
public void RunFile(string filePath)
326326
{
@@ -345,45 +345,45 @@ public void RunFile(string filePath)
345345
}
346346
}
347347

348-
public void RunFile(string filePath, bool showConsole)
349-
{
350-
if (RunDone)
351-
{
352-
RunDone = false;
353-
}
354-
ProcessStartInfo run0 = new ProcessStartInfo();
355-
run0.FileName = "python3_12\\python.exe";
356-
run0.Arguments = filePath;
357-
run0.UseShellExecute = false;
358-
if (!showConsole)
359-
{
360-
run0.RedirectStandardOutput = true;
361-
run0.CreateNoWindow = true;
362-
using (Process process = Process.Start(run0))
363-
{
364-
using (StreamReader reader = process.StandardOutput)
365-
{
366-
string result = reader.ReadToEnd();
367-
Console.WriteLine(result);
368-
RunDone = true;
369-
}
370-
}
371-
}
372-
else
373-
{
374-
run0.RedirectStandardOutput = false;
375-
run0.CreateNoWindow = false;
376-
using (Process process = Process.Start(run0))
377-
{
378-
using (StreamReader reader = process.StandardOutput)
379-
{
380-
string result = reader.ReadToEnd();
381-
Console.WriteLine(result);
382-
RunDone = true;
383-
}
384-
}
385-
}
386-
}
348+
//public void RunFile(string filePath, bool showConsole)
349+
//{
350+
// if (RunDone)
351+
// {
352+
// RunDone = false;
353+
// }
354+
// ProcessStartInfo run0 = new ProcessStartInfo();
355+
// run0.FileName = "python3_12\\python.exe";
356+
// run0.Arguments = filePath;
357+
// run0.UseShellExecute = false;
358+
// if (!showConsole)
359+
// {
360+
// run0.RedirectStandardOutput = true;
361+
// run0.CreateNoWindow = true;
362+
// using (Process process = Process.Start(run0))
363+
// {
364+
// using (StreamReader reader = process.StandardOutput)
365+
// {
366+
// string result = reader.ReadToEnd();
367+
// Console.WriteLine(result);
368+
// RunDone = true;
369+
// }
370+
// }
371+
// }
372+
// else
373+
// {
374+
// run0.RedirectStandardOutput = false;
375+
// run0.CreateNoWindow = false;
376+
// using (Process process = Process.Start(run0))
377+
// {
378+
// using (StreamReader reader = process.StandardOutput)
379+
// {
380+
// string result = reader.ReadToEnd();
381+
// Console.WriteLine(result);
382+
// RunDone = true;
383+
// }
384+
// }
385+
// }
386+
//}
387387

388388
public string GetOutput(string script)
389389
{

README.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dotnet add package CSSimpleFunctions --version [latest release version]
1515
- [Check](#check)
1616
- [Convert](#convert)
1717
- [PyCS](#pycs)
18+
- [SimpleFileHandler](#simplefilehandler)
1819

1920
## Check
2021
### HasNumbers
@@ -82,6 +83,11 @@ Check.Email.IsValid("test@outlook.com"); // returns false
8283
Check.Email.IsValid("test@asd.com"); // returns false
8384
```
8485
## Convert
86+
### Reverse
87+
- will reverse a String
88+
```csharp
89+
Convert.Reverse("Sample text"); // returns "txet elpmaS"
90+
```
8591
### ToBase64
8692
- will convert a String to its Base64 version
8793
- returns a String
@@ -94,7 +100,21 @@ Convert.ToBase64("Sample text"); // returns "U2FtcGxlIHRleHQ="
94100
```csharp
95101
Convert.FromBase64("U2FtcGxlIHRleHQ="); // returns "Sample text"
96102
```
103+
### ToByteArray
104+
- will convert a String to a byte array
105+
- returns a byte array
106+
```csharp
107+
byte[] byteArray = Convert.ToByteArray("Sample text");
108+
```
109+
### FromByteArray
110+
- will convert a byte array to a String
111+
- returns a String
112+
```csharp
113+
byte[] byteArray = Convert.ToByteArray("Sample text");
114+
string temp = Convert.FromByteArray(byteArray);
115+
```
97116
## PyCS
117+
Run Python 3.12 scripts and commands from C#
98118
### Initialization
99119
```csharp
100120
PyCS pycs = new PyCS();
@@ -107,7 +127,19 @@ PyCS pycs = new PyCS(false); // no console messages
107127
### Pip
108128
- starts a pip install command
109129
```csharp
110-
pycs.Pip(new string[]{"opencv-python"});
130+
pycs.Pip(new string[]
131+
{
132+
"numpy"
133+
});
134+
```
135+
### PipLocal
136+
- starts a pip install command for already downloaded .whl files
137+
```csharp
138+
pycs.PipLocal(new string[]
139+
{
140+
"numpy-2.2.6-cp312-cp312-win32.whl",
141+
"opencv_python-4.12.0.88-cp37-abi3-win32.whl"
142+
});
111143
```
112144
### Run
113145
- runs a given Python script in a string value
@@ -128,4 +160,20 @@ string text = pycs.GetOutput("print('Hello')"); // returns "Hello"
128160
- runs a given Python script in a given file path and returns the console message in a string value
129161
```csharp
130162
string text = pycs.GetFileOutput("scripts/hello.py"); // returns "Hello"
163+
```
164+
## SimpleFileHandler
165+
### Write
166+
- writes text to a file
167+
```csharp
168+
SimpleFileHandler.Write("path/to/file.txt", "Sample text");
169+
```
170+
### Read
171+
- reads text from a file
172+
```csharp
173+
string text = SimpleFileHandler.Read("path/to/file.txt");
174+
```
175+
### Append
176+
- appends text to a file
177+
```csharp
178+
SimpleFileHandler.Append("path/to/file.txt", "Sample text 2");
131179
```

0 commit comments

Comments
 (0)