0
I have a program in C# that uses a button to execute a command on the CMD. This command is used to take a database on a server and put it on the machine in a path you choose(Mysqldump).
private void button2_Click(object sender, EventArgs e)
{
string caminhoArq = Directory.GetCurrentDirectory();
string nomesever = (string)sever.Text;
string nomeuser = (string)user.Text;
string senha = (string)pass.Text;
string NumeroPorta = (string)porta.Text;
string banco = (string)comboBox1.Text;
string caminhoDoArquivo = (string)caminho.Text;
string data = DateTime.Now.ToString("dd-MM-yyyy");
try //Faz Backup
{
System.Diagnostics.Process.Start("CMD.exe", "/C \"" + caminhoArq + @"\FuncoesMySQL\mysqldump -u" + nomeuser + " -p" + senha + " -h" + nomesever + " -P" + NumeroPorta + " " + banco + " > " + caminhoDoArquivo + @"\" + banco + data + ".sql");
}
catch
{
MessageBox.Show("Erro ao Executar o Comando!");
}
MessageBox.Show("backup feito");
}
I use some char type variables to straighten the screen parameters and run the CMD. And it works perfectly!! But when the user name you a space, or even the path where the file will be placed has some space or accentuation, it does not execute the command on CMD.
I need to know how to make this command run on CMD correctly, even with these accentuation challenges.
Example of correct command:
System.Diagnostics.Process.Start("CMD.exe", "/C \"D:\FuncoesMySQL\mysqldump -uroot -p1234 -hservidor -P3305 bancoteste > C:\bancoteste18-02-2019.sql");
Put an example of how the call should look, please
– Andre.Santarosa
In general it is almost always enough to put snippets of code that contain space between quotation marks, to avoid errors. Have you tried this possibility?
– Caio de Paula Silva
how would you do it in this command?
– Pedro Stelita Vieira