C
C#2y ago
Maybe Ange

❔ [FIX} Csharp & Python / WPF APP

I have a problem with this code, in fact I have a button on my WPF software and when I click on it it executes a separate python script in another file. The problem is that the software returns me my error I made in "Try" and tells me that it can't find the file and it can't run it, yet I don't understand the path is ok , can someone help me?
private void Button_Click(object sender, RoutedEventArgs e)
{
string pythonPath = @"C:\Program Files\Python\Python39\python.exe";
string scriptPath = @"D:\Documents\Script security network\Software Box\Software\Reload Box\scripts\reload-no-time.py";

try
{
if (!File.Exists(scriptPath))
{
throw new FileNotFoundException("Le fichier de script n'existe pas", scriptPath);
}
}
catch (FileNotFoundException ex)
{
MessageBox.Show($"Erreur : {ex.Message}");
return;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
string pythonPath = @"C:\Program Files\Python\Python39\python.exe";
string scriptPath = @"D:\Documents\Script security network\Software Box\Software\Reload Box\scripts\reload-no-time.py";

try
{
if (!File.Exists(scriptPath))
{
throw new FileNotFoundException("Le fichier de script n'existe pas", scriptPath);
}
}
catch (FileNotFoundException ex)
{
MessageBox.Show($"Erreur : {ex.Message}");
return;
}
33 Replies
mtreit
mtreit2y ago
If it says the file does not exist it probably really does not exist. Are you sure the path is right? If you open a PowerShell window and type this what does it say?
dir "D:\Documents\Script security network\Software Box\Software\Reload Box\scripts\reload-no-time.py"
dir "D:\Documents\Script security network\Software Box\Software\Reload Box\scripts\reload-no-time.py"
Maybe Ange
Maybe AngeOP2y ago
Maybe Ange
Maybe AngeOP2y ago
mtreit
mtreit2y ago
I don't see any reason that code would fail then
✿ Scarlet ✿
why not just call "python"? it will work if you have the language properly installed in your OS since you have the path environment variable enabled
Maybe Ange
Maybe AngeOP2y ago
Maybe Ange
Maybe AngeOP2y ago
What?
mtreit
mtreit2y ago
Your error message is supposed to say this: | Le fichier de script n'existe pas But the error message you just showed does not say that. So is that error message coming from somewhere else?
✿ Scarlet ✿
yeah your program cant find python maybe? try only using "python" instead of the path just curious if itll work
Maybe Ange
Maybe AngeOP2y ago
Just python, how?
✿ Scarlet ✿
instead of passing the python path just type python [script path]
Maybe Ange
Maybe AngeOP2y ago
I'm not very strong in Csharp lmao, how?
✿ Scarlet ✿
are you instancing a new Process? to execute the script? can you show that part of the code?
Maybe Ange
Maybe AngeOP2y ago
No
✿ Scarlet ✿
put breakpoints in your errors your screenshot dont fit with the code you are showing
Maybe Ange
Maybe AngeOP2y ago
✿ Scarlet ✿
As I said, you are instancing a new Process can you show the entire code?
✿ Scarlet ✿
Is your Python path really correct? I mean, your script path is correct
Maybe Ange
Maybe AngeOP2y ago
Mhm
✿ Scarlet ✿
but how about the Python exe ?
Maybe Ange
Maybe AngeOP2y ago
Maybe Ange
Maybe AngeOP2y ago
Oh script path?
✿ Scarlet ✿
no you are using the wrong python path
Maybe Ange
Maybe AngeOP2y ago
Oh
✿ Scarlet ✿
check the screenshot you sent now and check your code
Maybe Ange
Maybe AngeOP2y ago
Okay, Now I don't have the same code anymore depending on the 2 locations I put wait
Maybe Ange
Maybe AngeOP2y ago
With: C:\Users\Cooky\AppData\Local\Programs\Python\Python311\python.exe
Maybe Ange
Maybe AngeOP2y ago
With: C:\Users\Cooky\AppData\Local\Microsoft\WindowsApps\python.exe
Maybe Ange
Maybe AngeOP2y ago
"Script exited with error code"
Maybe Ange
Maybe AngeOP2y ago
Maybe Ange
Maybe AngeOP2y ago
Mhmmm 🤔 My script works perfectly locally, why not from here?
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server