none
Can't run command neither as Shell nor Process.Start

    Question

  • I have to back mysql database up. Mysql utility mysqldump.exe works just fine, but I would run it from my app, not from batch file or cmd.exe.

    Here the batch file content:

    c:\mysql\bin\mysqldump.exe -u root --databases basename > c:\basename.sql

    it works. How can I do from my app without starting cmd or batch?

    I tried to do it in two ways:

    Shell("c:\mysql\bin\mysqldump.exe  -u root --databases basename > c:\basename.sql")

    and

    Dim ProcessProperties As New ProcessStartInfo       

    ProcessProperties.FileName = "c:\mysql\bin\mysqldump.exe"       

    ProcessProperties.Arguments = " -u root --databases basename > c:/basename.sql" 'command line arguments       

    ProcessProperties.WorkingDirectory = "C:\"       

    ProcessProperties.WindowStyle = ProcessWindowStyle.Maximized       

    Dim myProcess As Process = Process.Start(ProcessProperties)

    Nothing. Black window with a bunch of symbols appears for a few milliseconds and disappears. I looked through all the drive for output file, but can't found it.

    What is wrong here?


    • Edited by Ha3R Thursday, July 04, 2013 7:50 PM edit
    Thursday, July 04, 2013 7:47 PM

Answers

  • Do you normally run the program from the C:\  or from another folder?  Are you running with admin prioviledges?  try running from a different working folder.  You have a space at the beginning of the Arguements which is unnecessary, and probably not causing any problems.  I would eliminate the space anyway.  You may want to try the following

    ProcessProperties.FileName = "c:\windows\system32\cmd.exe" 

    ProcessProperties.Arguments = "c:\mysql\bin\mysqldump.exe -u root --databases basename > c:/basename.sql"


    jdweng

    • Marked as answer by Ha3R Friday, July 05, 2013 6:28 AM
    Thursday, July 04, 2013 8:44 PM
  • Please try what Joel Engineer posted, you may need to prepend either "/c" or "/k" to the arguments line

    As in :

    ProcessProperties.Arguments = "/k c:\mysql\bin\mysqldump.exe -u root --databases basename > c:/basename.sql"

    /c : Carries out the command specified by string and then stops.
    /k : Carries out the command specified by string and continues.

    • Marked as answer by Ha3R Friday, July 05, 2013 6:27 AM
    Friday, July 05, 2013 1:19 AM

All replies

  • Do you see a command line window open? What kind of application are you running it from?

    Thursday, July 04, 2013 8:19 PM
  • Do you normally run the program from the C:\  or from another folder?  Are you running with admin prioviledges?  try running from a different working folder.  You have a space at the beginning of the Arguements which is unnecessary, and probably not causing any problems.  I would eliminate the space anyway.  You may want to try the following

    ProcessProperties.FileName = "c:\windows\system32\cmd.exe" 

    ProcessProperties.Arguments = "c:\mysql\bin\mysqldump.exe -u root --databases basename > c:/basename.sql"


    jdweng

    • Marked as answer by Ha3R Friday, July 05, 2013 6:28 AM
    Thursday, July 04, 2013 8:44 PM
  • Do you see a command line window open? What kind of application are you running it from?

    Yeah, I see it, and a content of a backup that should be stored to file scrolling in that window. Window appears, but no file created.


    I'm running this code from my app (windows form app)
    • Edited by Ha3R Thursday, July 04, 2013 9:07 PM edit
    Thursday, July 04, 2013 9:06 PM
  • Do you normally run the program from the C:\  or from another folder?  Are you running with admin prioviledges?  try running from a different working folder.  You have a space at the beginning of the Arguements which is unnecessary, and probably not causing any problems.  I would eliminate the space anyway.  You may want to try the following

    ProcessProperties.FileName = "c:\windows\system32\cmd.exe" 

    ProcessProperties.Arguments = "c:\mysql\bin\mysqldump.exe -u root --databases basename > c:/basename.sql"


    jdweng

    I tried to run my app from C:\ as well as from project's bin\release directory.

    Logged as admin (windows xp). The space on command line is not an issue, tried without that leading space.

    When running cmd itself with mysqldump as command line option, only empty cmd window appears and waits for user input. Nothing more.

    P.S.

    Also tried to write file name as c:\basename.sql instead of c:/basename.sql.

    Relative file name  "basename.sql" only was tried as well


    • Edited by Ha3R Thursday, July 04, 2013 9:20 PM edit
    Thursday, July 04, 2013 9:13 PM
  • If your OS is Windows 7 or newer, then try to avoid to use direct the root of the boot drive as a working directory.


    Success
    Cor

    Thursday, July 04, 2013 10:09 PM
  • Please try what Joel Engineer posted, you may need to prepend either "/c" or "/k" to the arguments line

    As in :

    ProcessProperties.Arguments = "/k c:\mysql\bin\mysqldump.exe -u root --databases basename > c:/basename.sql"

    /c : Carries out the command specified by string and then stops.
    /k : Carries out the command specified by string and continues.

    • Marked as answer by Ha3R Friday, July 05, 2013 6:27 AM
    Friday, July 05, 2013 1:19 AM
  • Yeah, it does the trick!

    Works fine if command line arguments prepended with /c.

    Thanks for help, guys!

    Friday, July 05, 2013 6:22 AM