Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

____________________________________________

http://www.pophamcafe.com

I am starting a developers section, more tutorials than anything.

Posted
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();

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.

Posted

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

____________________________________________

http://www.pophamcafe.com

I am starting a developers section, more tutorials than anything.

Posted (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 by Joe Mamma

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.

Posted

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?

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.

Posted

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.

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.

Posted

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

____________________________________________

http://www.pophamcafe.com

I am starting a developers section, more tutorials than anything.

Posted

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!

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.

Posted

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()

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...