C
C#13mo ago
bribri

start an python script from an c# project

How can I start my python script from an c# project? My solution looks like this at the moment but not really sure how to let it run ( i'm testing some things so my solution explorer looks really bad....)
15 Replies
HimmDawg
HimmDawg13mo ago
Should be as simple as running the script in a Process fluffyFoxThink
Chiyoko_S
Chiyoko_S13mo ago
yeah just run the python script using the python interpreter you can do that in C# using Process although it is questionable why you'd want to do that? is it not possible to just have everything in C# or Python
bribri
bribri13mo ago
its more a testing thing
Chiyoko_S
Chiyoko_S13mo ago
I see
bribri
bribri13mo ago
and how does process work? tried some things
Chiyoko_S
Chiyoko_S13mo ago
it is pretty similar to how you execute files in command line you have a program, and you feed it arguments / etc to it to start executing in this case the program would be the python interpreter
bribri
bribri13mo ago
arion
arion13mo ago
Process.Start("py", "myscript.py");
Process.Start("py", "myscript.py");
or python3, etc 1st parameter is the file, 2nd is the arguments
bribri
bribri13mo ago
yes thanks!!! finally works. Thank you so much!
arion
arion13mo ago
Just remember that the method will fail if there is no python installed
bribri
bribri13mo ago
And how can I make it work if I want it to always work?
arion
arion13mo ago
<:poi_shrug:582941309174546569> Ensure python is installed before running the method There's also other libraries like IronPython though I've never used python in c#
phaseshift
phaseshift13mo ago
Embed an archive of python3. Unpack it when your app starts. Lol
arion
arion13mo ago
If you've never done embedding files into your program before, this tutorial explains pretty much exactly what you'd need to do https://www.c-sharpcorner.com/UploadFile/40e97e/saving-an-embedded-file-in-C-Sharp/ (Skip the first step of course "Step 1. Create a new Console Application")
Want results from more Discord servers?
Add your server
More Posts
Getting a SQL compilation error, object $$ does not exist or not authorized on Visual StudioI was wondering if anyone has come across the same issue? I'm getting this error on macOS, the same ❔ Using STARTUPINFOEXW on PInvoke.CreateProcess - how to move from ref / out to pointer?I'm using CsWin32 but I'm having trouble calling `PInvoke.CreateProcess` using a `STARTUPINFOEXW` in❔ Refresh WriteableBitmapHi, I would like to use a WriteableBitmap in my application. However, the Image control does not upd✅ Semicolon expectedI have error in this string: `Cell1609.Text += "<span style="color:red;">Blocked</span>";` the prob❔ ✅ Could not load file or assembly Microsoft.Bcl.AsyncInterfaces 7.0.0.0I've upgaded the packages of about 100 csproj in multiple solutions and now each service logs: ```cs✅ Abstraction Final ProjectSo this is my first semester doing anything related to C# and I've kind of ridden coattails on other.NET MAUI ImageSource from saved ByteArrayThis is currently how im trying to display 3 images from a sql query however im returning byte array✅ Member '<member name>' cannot be accessed with an instance reference```cs namespace palidromeDepth { internal class Program { static void Main(string[] ❔ Missing assembly reference using PackageReferenceI updated to package references a short while ago, now when I change development environments (git cUnsure when to load data .NET MAUII am trying to load the Ingredient value from my sqlite db and it doesnt load when im calling it wit