I am trying to run a command line program to backup mysql, from within Servoy. I am not getting any output, any error messages, or any feedback. Here is my code:
var program_output = application.executeProgram('C:/Program Files/MySQL/MySQL Server 5.0/bin/mysqldump',
'-u',
'dbuser',
'-pmypw',
'user_data',
'>',
'c:/temp/user_data.sql',
'#',
'path=C:/Program Files/MySQL/MySQL Server 5.0/bin',
'#',
'c:/temp'
);
As a simple test, I ran this code and it worked fine:
var program_output = application.executeProgram('notepad')
I’ve read everything I can find, including these posts. I’m not seeing any examples where all three options are used in the executeProgram() syntax (parameters, environ variables, and start directory). I’m using environment variables to set the path and I’m using the [startdir] option to start my program in a particular directory.
From what I can see, my syntax looks correct and I’m not getting any errors back. The variable returned doesn’t have any messages in it either, so I can see if something is going wrong.
I’ve looked at the server log and there’s nothing there.
Can someone that uses mysql try this code and see if it works for you?
I have tried running it as one line with no difference.
I’m not sure if using a batch file will be any different, unless servoy happens to like them better than an .exe file. I’ll try it and see how that works. This might be the work-around.
I’m trying to make a dynamic call to mysqldump so I can backup my data from within Servoy, so I’ll need to feed it parameters each time --it won’t be a fixed call.
The ‘>’ argument will cause a problem.
You probably want to redirect the output to a file, ‘>’ is not valid argument to the program (it is is recognized by the windows command interpreter, but that is not used in this context)
Try using the ‘-r’ argument of mysqdump, it will tell it to direct the output to the file argument.
I finally got the batch file to work, as Marcel suggested. Thank you M. I had to feed it parameters to change drives and directories, so I got something running I think I can mold into what I want.
I finally found the ‘-r’ documented as an option for mysqldump to redirect the output. They show ‘–result-file=file’, but that didn’t work either in this function call. Buried down below in their docs was a reference to “-r”.
I could not get the start directory to work according to the syntax in the sample code for executeProgram(). It always returned an error saying ‘#’ was not a valid directory. I put in no parameters, fake parameters, real parameters, etc but always got the same error message. Not sure the ‘#’ is really supported in the 3.5.6 version. If so, can you please explain the syntax?
//Execute a program and returns output, specify the cmd as you would do in a console
//'#' is divider between program args, environment vars and startdir
var program_output = application.executeProgram('c:/temp/program.ext','arg0','arg1','argN','#','path=c:/temp','#','c:/temp');
So I’m thinking this is incorrect syntax they’re providing in they sample.
Can someone at Servoy clarify the syntax of the executeProgram() method for all of the options, and provide a working example?
The one thing I’d like to understand is how to make it run the program from the [startdir] directory.
Using global variables on my form, I am able to specify the database and the save location, hit a button, and make a quick backup of a mysql database. Now I can get fancy with the UI to show the available databases, save preferences, re-import a backup if desired, etc.
I would still like to see some examples from the servoy staff for using the ‘#’ to separate parameters, environ variables, and a start directory. The start directory would be very useful. I coded around it in the above example, but would still like to see the proper syntax.
There is actually an issue with the start directory and env variables in app.executeProgram().
This will be fixed in next release.
Note that executeProgram runs on the machine that runs the jvm.
In case of webclient and batch processor, it is the server, in case of the smart client it is the client machine.