Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DOS command box 1

Status
Not open for further replies.

Jerryyang

Programmer
Feb 15, 2011
8
CA
I'm using RUN command inside the VFP, it will pop-up a DOS command box.
how can I make it silent?
thanks for the help

 
A lot depends on what you're trying to RUN.

RUN /N might take care of it.

Or you may be better served by the API ShellExecute() function, which is available either as a pure API call or as an automation call through Wscript.Shell.

But it's hard to guess with the details you haven't given.
 
I want to run the backup using mysqldump.exe
I'm using VFP 9 with MySQL database.

I tried:
RUN mysqldump -umyid -pmypass admdata > c:\backup1.txt
RUN /n mysqldump -umyid -pmypass admdata > c:\backup2.txt
RUN mysqldump -umyid -pmypass admdata > c:\backup3.txt /n

the first one (without /n) creates a complete backup file.
the second one (with /n) doesn't create any file.
the third on (with /n at the back) create an empty file

Thanks for the help.
 
I'll provide one more exhibit of my ignorance by saying that I haven't worked with MySQL very much and therefore don't know it very well.

But, my ignorance aside, can you create a Stored Procedure resident within the MySQL database itself which can run your backups?

If so then you should be able to launch it from your VFP9 application with a SQLEXEC() and have it run 'on its own' without displaying the DOS Black Box.

Good Luck,
JRB-Bldr
 
Thanks for the input.

I have a form with plenty of options, the clients can choose certain date, certain files, etc. it's easy to manage within the form and then execute the backup.
 
Thanks for the suggestion.
only I don't want the client to know the database's user id and password.
 
You could always write the batch file so that it receives the login ID and password as parameters. For example:

Code:
mysqldump -%1 -%2 admdata > c:\backup1.txt
mysqldump -%1 -%2 admdata > c:\backup2.txt
mysqldump -%1 -%2 admdata > c:\backup3.txt

The ShellExecute() would then pass the parameters, like this:

Code:
ShellExecute(0, "open", "c:\MyBatchFile.BAT", ;
  "umyid, pmypass", "", 1)

That way, the ID and password would not be visible to anyone who opens the batch file.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I have tried with batch file, it works perfectly, thank you so much.

if I call directly with ShellExecute(), it doesn't work, it has to be with batch file.
 
Well, you have to specify mysqldump.exe in a ShellExecute(), maybe even with the full path and there may be other issues you did wrong with the ShellExecute call. Can't tell, if you don't post your non working ShellExecute().

Bye, Olaf.
 


This works:

MyBatchFile.BAT
Code:
mysqldump -%1 -%2 %3 > %4

and:
Code:
ShellExecute(0, "open", "c:\MyBatchFile.BAT", "umyid, pmypass, admData, c:\backup1.txt", "", 0)

These don't work:
Code:
ShellExecute(0, "open", "mysqldump",     "-umyid -pmypass admData > c:\backup1.txt", "", 0)
ShellExecute(0, "open", "mysqldump.exe", "-umyid -pmypass admData > c:\backup1.txt", "", 0)
ShellExecute(0, "open", "mysqldump     -umyid -pmypass admData > c:\backup1.txt","","", 0)
ShellExecute(0, "open", "mysqldump.exe -umyid -pmypass admData > c:\backup1.txt","","", 0)
 
...with the full path..."

ShellExecute doesn't search where mysqldump.exe is located. A batchfile does make use of the system environment variable %PATH%, ShellExecute does not!

ShellExecute(0, "open", "C:\Program Files\...\mysqldump.exe", "-umyid -pmypass admData > c:\backup1.txt", "", 0)

Bye, Olaf.
 
ShellExecute returns a value, see what it means here in the "Return Value" section:
I'm pretty sue you get "ERROR_FILE_NOT_FOUND" or "SE_ERR_FNF", which means ShellExecute() returns 2.

Here are all error constant definitions (contained in shellapi.h):
Code:
#define SE_ERR_SHARE            26
#define SE_ERR_ASSOCINCOMPLETE  27
#define SE_ERR_DDETIMEOUT       28
#define SE_ERR_DDEFAIL          29
#define SE_ERR_DDEBUSY          30
#define SE_ERR_NOASSOC          31

#define SE_ERR_FNF              2       
#define SE_ERR_PNF              3       
#define SE_ERR_ACCESSDENIED     5       
#define SE_ERR_OOM              8       
#define SE_ERR_DLLNOTFOUND      32
#define SE_ERR_SHARE                    26
#define SE_ERR_ASSOCINCOMPLETE          27
#define SE_ERR_DDETIMEOUT               28
#define SE_ERR_DDEFAIL                  29
#define SE_ERR_DDEBUSY                  30
#define SE_ERR_NOASSOC                  31

Bye, Olaf.
 
Jerryyang,

Your first ShellExecute() is fine. Your second one didn't work because you are doubling up the hyphens.

This is what you did:

Code:
ShellExecute(0, "open", "mysqldump",     "[b]-[/b]umyid [b]-[/b]pmypass admData > c:\backup1.txt", "", 0)

You see those hyphens before umyid and pmypass. The batch file also has hyphens in those places, so, after the parameters have been substituted, you get a double hyphen in each place.

Also, I'm not sure if ShellExecute() can handle the redirection character.

So, stay with this one:

Code:
ShellExecute(0, "open", "c:\MyBatchFile.BAT", "umyid, pmypass, admData, c:\backup1.txt", "", 0)

and everything should be fine.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top