J'ai un petit problème pour exécuter une commande linux depuis un script c#.
J'aimerais pouvoir lancer un "fichier" depuis le c# (qui correspond du coup à un logiciel), du coup j'essais de lancer 2 commandes:
La première étant de pouvoir autoriser le fichier à être un fichier exécutable en faisant :
Code : Tout sélectionner
private void ChmodCommand(string filePath)
{
var escapedArgs = filePath.Replace("\"", "\\\"");
var process = new Process()
{
StartInfo = new ProcessStartInfo
{
FileName = "/bin/bash",
Arguments = $"-c chmod +x \"{escapedArgs}\"",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
}
};
process.Start();
string result = process.StandardOutput.ReadToEnd();
process.WaitForExit();
}
Code : Tout sélectionner
public string Execute(string filePath)
{
var escapedArgs = filePath.Replace("\"", "\\\"");
var process = new Process()
{
StartInfo = new ProcessStartInfo
{
FileName = "/bin/bash",
Arguments = $"-c \"{escapedArgs}\"",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
}
};
process.Start();
string result = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return result;
}
" Win32Exception: ApplicationName='/bin/bash', CommandLine='-c chmod +x "/home/etc...,
CurrentDirectory='', Native error= mono-io-layer-error (0) at System.Diagnostics.Process.StartWithCreateProcess (System.Diagnostics.ProcessStartInfo startInfo) [0x00000] in <00000000000000000000000000000000>:0" etc....
Donc voila, si quelqu'un a une idée ou des pistes, je suis preneur,
Merci bien!