Search code examples
c++windowswinformscmdc++-cli

how to run 2 commands using one system() function in c++


I want to execute 2 cmd commands in one system () function c++ but one cmd command passed as a concatenation:

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

            System::String^ managedString = textBox1->Text; 

             msclr::interop::marshal_context context;
    std::string standardString = context.marshal_as<std::string>(managedString);

    std::string s2 = "yara64 -r test.yara " + standardString;

    system(s2.c_str() && "pause");

}

this code doesn't work. this works only if I remove "pause" command. How to execute exactly with "pause" command in one system ()?

Please help me. Thanks a lot!


Solution

  • make the "&&" part of the string itself.

    std::string s2 = "yara64 -r test.yara " + standardString + "&& pause";
    system(s2.c_str());