|
|
Home » Developing U++ » U++ Developers corner » evaluate command line (parse line by line processed command to create backup log)
evaluate command line [message #58686] |
Thu, 21 July 2022 22:04  |
BetoValle
Messages: 204 Registered: September 2020 Location: Brasil Valinhos SP
|
Experienced Member |
|
|
I found this code below and tested it successfully. But my intention is to evaluate the contents of each line that the mysqldump program generates. How to do this? Could someone help me with an example?
Grateful!
CONSOLE_APP_MAIN
{
std::stringstream ss;
std::string pathOfCommand ="C:\\Program Files (x86)\\MariaDB 10.1\\bin\\mysqldump.exe";
std::string params=" -u mylogin --password=mypass --verbose --extended-insert=FALSE databaseName > ";
std::string pathOfInputFile="C:\\TEMP\\file1.sql";
// some code to set values for paths and solves the filename space problem
ss << "\""; // command opening quote
ss << "\"" << pathOfCommand << "\" "; // Quoted binary (could have spaces)
ss << " " << params << " "; // Quoted input (could have spaces)
ss << "\"" << pathOfInputFile << "\""; // Quoted input (could have spaces)
ss << "\""; // command closing quote
Cout() << "seeing how the command turned out:" << ss.str() << EOL;
int i;
i=system( ss.str().c_str() );
Cout() <<"backup result: " << i << EOL;
}
|
|
|
|
|
|
Re: evaluate command line [message #58690 is a reply to message #58689] |
Fri, 22 July 2022 21:48   |
jjacksonRIAB
Messages: 227 Registered: June 2011
|
Experienced Member |
|
|
Yeah dir might not work if you're in an empty directory or the delimiter is not a newline (I think it is even under Windows though). There's a function called
ChangeCurrentDirectory("whatever");
There are also several functions for reading in environment variables that could prove useful to you in certain contexts. Ex.
Cout() << GetEnv("PATH");
Will print out a PATH environment variable in a unix-like or DOS. There's also GetHomeDirectory(), GetProgramsFolder(), GetProgramsFolderX86(), GetTempDirectory() and a few others - I believe all of those call GetEnv with known environment variables.
I don't know anything about MariaDB but it may be preferable to find some kind of environment variable or registry key to locate where mysqldump.exe so your don't have to hardcode anything (knowing Windows it could be installed in one of several places or even on a different drive). Sometimes that can't be helped though... and if it's just for personal use who cares, I guess... but if, for example, someone put their Programs Folder on the D: or E: drive instead of C:, some of the functions above can help you clean up your application discovery process.
**EDIT** Looking at Windows, it appears to do things differently. If I use "cmd /c dir" it will print out and split everything correctly but you might want LocalProcess instead. I don't know offhand how to create this process without creating a Window because I just remembered that dir is not actually a separate program under Windows, it's a built-in shell command. There's probably some argument that be passed to hide the window.
https://www.ultimatepp.org/src$Core$AProcess$en-us.html
[Updated on: Fri, 22 July 2022 23:43] Report message to a moderator
|
|
|
|
|
Re: evaluate command line [message #58693 is a reply to message #58692] |
Sat, 23 July 2022 01:51  |
BetoValle
Messages: 204 Registered: September 2020 Location: Brasil Valinhos SP
|
Experienced Member |
|
|
ok! very good! now work with command "dir".
"Sys" on windows 10, no console window opens!
CONSOLE_APP_MAIN
{
String output;
Sys("cmd.exe /c dir c:\\temp", output);
Cout() << "aqui " << output << EOL;
Vector<String> lines = Split(output, "\n");
int i = 1;
for(auto& line : lines) {
Cout() << Format("Line #%d: %s\n", i, line);
i++;
}
}
|
|
|
Goto Forum:
Current Time: Sun May 11 01:43:08 CEST 2025
Total time taken to generate the page: 0.03208 seconds
|
|
|