cpopham Posted July 22, 2005 Posted July 22, 2005 I am trying to use a process start to do a mysql dump. The -u and -p are swicthes that tell the executable what to do. I see the dos window open and close and no errors, but the dump file c:\test.sql is not created. System.Diagnostics.Process.Start("C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqldump.exe", "-u root -pchecli02 myacct > c:\test23.sql") Any ideas? Thanks Chester Quote ____________________________________________ http://www.pophamcafe.com I am starting a developers section, more tutorials than anything.
Joe Mamma Posted July 22, 2005 Posted July 22, 2005 ProcessStartInfo ps = new ProcessStartInfo(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqldump.exe",@"-u root -pchecli02 myacct"); ps.UseShellExecute = false; ps.RedirectStandardOutput = true; Process p=new Process(); p.StartInfo = ps; p.Start(); using (System.IO.StreamWriter sw = new System.IO.StreamWriter(@"c:\test23.sql")) sw.Write(p.StandardOutput.ReadToEnd()); p.WaitForExit(); Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
cpopham Posted July 22, 2005 Author Posted July 22, 2005 Thanks Joe Mamma, That did the trick..... Why do you have to use a streamwriter though for the output? Thanks, Chester Quote ____________________________________________ http://www.pophamcafe.com I am starting a developers section, more tutorials than anything.
cpopham Posted July 23, 2005 Author Posted July 23, 2005 Now how can I reverse this process to read the file backup? I have tried the following code without success: ps.UseShellExecute = False ps.RedirectStandardOutput = True Dim p As Process p = New Process p.StartInfo = ps p.Start() Dim sw As New System.IO.StreamReader("C:\testNew.sql") sw.Read(p.StandardInput) p.WaitForExit() Thank You.. Chester Quote ____________________________________________ http://www.pophamcafe.com I am starting a developers section, more tutorials than anything.
Joe Mamma Posted July 23, 2005 Posted July 23, 2005 (edited) first. . . the streamwriter worked? I just hacked that out of the MSDN help. the reason your first example failed is that the " > testNew.sql " part of the command line are not arguments but output redirection. Now what to you mean reverse? Can you post the command line you want to emulate including any I/O redirections? Edited July 23, 2005 by Joe Mamma Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Joe Mamma Posted July 23, 2005 Posted July 23, 2005 and answering your question. . . wouldnt the reverse actually be: Dim sw As New System.IO.StreamReader("C:\testNew.sql") p.StandardInput.Write(sw.ReadToEnd()) StandardOutput is a streamreader - only has read methods StandardInput is a streamwriter - has write methods. Conceptually you want to Write from a file to the process' StandardInput and Read the process' StandardOutput into a file. make sense? Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Joe Mamma Posted July 23, 2005 Posted July 23, 2005 oh yeah - In VB.NOT remember to close your stream readers/writers to free resources. In C# I wrap in a using statement to automatically close. Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
cpopham Posted July 23, 2005 Author Posted July 23, 2005 What my overall goal is is to use the builtin mysqldump application to backup a mysql database and then should something happen, I want to be able to restore from the backup that was generated. Yes your sample worked very well. I tried using the streamreader to reverse the process. Using mysqldump, You would use a statement like: mysqldump -u myuser -pmypassword mydatabasetorestoreto < mybackup.sql The only difference in the statements in mysql is the greater than or less than sign.. Thanks, Chester Quote ____________________________________________ http://www.pophamcafe.com I am starting a developers section, more tutorials than anything.
Joe Mamma Posted July 23, 2005 Posted July 23, 2005 then I think it is:[color=black]dim ps = as ProcessStartInfo = new ProcessStartInfo(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqldump.exemysqldump -u myuser -pmypassword mydatabasetorestoreto")[/color] ps.UseShellExecute = False ps.RedirectStandardOutput = True Dim p As Process p = New Process p.StartInfo = ps p.Start() Dim sr As New System.IO.StreamReader("C:\testNew.sql") p.StandardInput.Write(sr.ReadToEnd()) p.WaitForExit() ' remember to close your streamreader sr.Close() again. . . I am thinking that will work. let me know! Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
cpopham Posted July 24, 2005 Author Posted July 24, 2005 I am getting the error that says: StandardIn has not benn redirected Chester Quote ____________________________________________ http://www.pophamcafe.com I am starting a developers section, more tutorials than anything.
Joe Mamma Posted July 24, 2005 Posted July 24, 2005 oops!!! [color=black]dim ps = as ProcessStartInfo = new ProcessStartInfo(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqldump.exemysqldump -u myuser -pmypassword mydatabasetorestoreto")[/color] ps.UseShellExecute = False [b]ps.RedirectStandardInput = True[/b] Dim p As Process p = New Process p.StartInfo = ps p.Start() Dim sr As New System.IO.StreamReader("C:\testNew.sql") p.StandardInput.Write(sr.ReadToEnd()) p.WaitForExit() ' remember to close your streamreader sr.Close() Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.