Witam.
Coś w tej funkcji powoduje 17 błędów. Co to takiego może być?
Pozdrawiam
string pwshellWithReturnment(string command) {
string returnment = "";
string tempstr = to_string((rand() % 99999999999) + 7);
//https://stackoverflow.com/questions/62469810/get-powershell-script-output-from-c-app
string psfilename = "%temp%\\a\\"; psfilename.append(tempstr.c_str());
string resfilename = "%temp%\\b\\"; resfilename.append(tempstr.c_str());
std::ofstream psfile;
psfile.open(psfilename);
//redirect the output of powershell into a text file
std::string powershell = "ls > " + resfilename + "\n";
psfile << powershell << std::endl;
psfile.close();
system(command.c_str());
//"start": run in background
system((std::string("powershell.exe ") + psfilename).c_str());
remove(psfilename.c_str());
//after the exe finished, read the result from that txt file
std::ifstream resfile(resfilename);
std::string line;
if (resfile.is_open()) {
std::cout << "result file opened" << std::endl;
while (getline(resfile, line)) {
std::cout << line << std::endl;
}
resfile.close();
remove(resfilename.c_str());
}
return returnment;
}