Exécuter succession de commande (sous cmd).
Je rencontre un petit soucis avec l'éxécution de commande dos via C#.
Je voudrais exécuter ces deux commandes. Qaund je passe par Windows, cela fonctionne.
Code:
1 2
| SET PGPASSWORD=123456789
"C:\Program Files\PostgreSQL\9.0\bin\pg_dump" -i -h 1127.0.0.1 -p 5432 -U postgres -F c -b -v -f C:\backup.backup nameDatabase |
Par contre quand je le fait côté C#, il me demande le mot de passe. Comme s'il ne tenait pas compte de la ligne
SET PGPASSWORD=123456789
Voici la fonction que j'utilise
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| public void ExecuteCommandSync(string command)
{
try
{
var processStartInfo = new ProcessStartInfo("cmd","/c "+command){
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = false,
WindowStyle = ProcessWindowStyle.Hidden
};
var process = new Process { StartInfo = processStartInfo };
process.Start();
var result = process.StandardOutput.ReadToEnd();
Console.WriteLine(result);
}
catch (Exception objException)
{
}
} |
Je pense qu'entre les 2 commandes, il doit falloir utiliser la même "session", mais je n'arrive pas à le faire fonctionner.
Qualqu'un peut il me donner un coup de main svp?
Merci