Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » evaluate command line (parse line by line processed command to create backup log)
Re: evaluate command line [message #58687 is a reply to message #58686] Fri, 22 July 2022 04:19 Go to previous messageGo to previous message
jjacksonRIAB is currently offline  jjacksonRIAB
Messages: 220
Registered: June 2011
Experienced Member
Try the Sys method instead, you don't need any of that std::string stuff, just String works fine:

#include <Core/Core.h>

using namespace Upp;

CONSOLE_APP_MAIN {
    String output;
    Sys("ls -la", output);
   
    Vector<String> lines = Split(output, "\n");

    int i = 1;
    for(auto& line : lines) {
        Cout() << Format("Line #%d: %s\n", i, line);
        i++;
    }
}


Sys will run the command and store the results in the output variable. Split will create an array of Strings that you can loop through on newline or you can choose an alternative delimiter. If you need anything more complex than that try looking up CParser (https://www.ultimatepp.org/src$Core$CParser_en-us.html), it can help you write a hand parser. Regexps are also available (https://www.ultimatepp.org/reference$RegExp$en-us.html).

I don't have Windows installed but if you replace "ls -la" with "dir" that example should get you going.

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: log file in Oracle8
Next Topic: Windows 11 toolbar and menu issues
Goto Forum:
  


Current Time: Fri May 03 23:33:34 CEST 2024

Total time taken to generate the page: 0.02117 seconds