Josh Posted March 25, 2017 Share Posted March 25, 2017 When Leadwerks Editor runs a game compiled as a Windowed application (no console) it successfully prints the game's output, even though there is no console. When a bat file is used to do the same thing, no text is printed. Is there a way to do this? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Crazycarpet Posted March 25, 2017 Share Posted March 25, 2017 You mean forward console output to a file? Run the program with the command line parameter: "> "output.txt"" or whatever file you want it to forward stdout to. Example bat file: start "Hale3DEditor" "Hale3DEditor-Debug.exe" "> console.txt" Quote Link to comment Share on other sites More sharing options...
Josh Posted March 26, 2017 Author Share Posted March 26, 2017 No, I mean actually print / echo the output of a winnowed application. The console of a bat file only shows the output of a console application. It does not show the output of a windowed application, even though Leadwerks editor shows it, and it can be printed to a text file with a bat file. So what is the default > setting to make a bat file actually show the text the program it runs? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Crazycarpet Posted March 26, 2017 Share Posted March 26, 2017 Oh, I don't know... I feel like if the output isn't already being redirected it should print to the console by default. I don't know how you'd do this if it's not already doing it, sorry. Edit: -Keep in mind if the application doesn't open it's own console it has no object to pass stdout to... it'd be NULL, so unless you could set from C++ the console to redirect stdout to (the one created by the batch file) this might not be do-able. If you wanted to build it right into the engine you could create a console and redirect stdout and what not, stderr, etc... but other then that idk. Quote Link to comment Share on other sites More sharing options...
IgorBgz90 Posted March 26, 2017 Share Posted March 26, 2017 Hi Josh, A couple of years ago I made my dedicated server (app) for minecraft=), there for interception from the console I used pipes. But, this is works only in windows. #include <windows.h> #include <iostream> #include <string> #include <stdio.h> #pragma warning(disable : 4996) // For GetVersionEx #define bzero(a) memset(a,0,sizeof(a)) char buf[1024]; STARTUPINFO si; SECURITY_ATTRIBUTES sa; SECURITY_DESCRIPTOR sd; PROCESS_INFORMATION pi; HANDLE newstdin, newstdout, read_stdout, write_stdin; unsigned long bread; unsigned long avail; bool IsWinNT() { OSVERSIONINFO osv; osv.dwOSVersionInfoSize = sizeof(osv); GetVersionEx(&osv); return (osv.dwPlatformId == VER_PLATFORM_WIN32_NT); } std::wstring s2ws(const std::string& s) { int len; int slength = (int)s.length() + 1; len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0); wchar_t* buf = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len); std::wstring r(buf); delete[] buf; return r; } bool CreateAnonymousPipes(std::string procName) { if (IsWinNT()) { InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION); SetSecurityDescriptorDacl(&sd, true, NULL, false); sa.lpSecurityDescriptor = &sd; } else { sa.lpSecurityDescriptor = NULL; } sa.nLength = sizeof(SECURITY_ATTRIBUTES); sa.bInheritHandle = true; //CreatePipe(&newstdin, &write_stdin, &sa, 0); //stdin CreatePipe(&read_stdout, &newstdout, &sa, 0); //stdout GetStartupInfo(&si); si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE; si.hStdOutput = newstdout; si.hStdError = newstdout; //si.hStdInput = newstdin; std::wstring stemp = std::wstring(procName.begin(), procName.end()); if (CreateProcess(stemp.c_str(), NULL, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, π)) { return true; } bzero(buf); return false; } // Child process stdout void ReceiveChild() { PeekNamedPipe(read_stdout, buf, 1023, &bread, &avail, NULL); if (bread != 0) { bzero(buf); if (avail > 1023) { while (bread >= 1023) { ReadFile(read_stdout, buf, 1023, &bread, NULL); bzero(buf); } } else { ReadFile(read_stdout, buf, 1023, &bread, NULL); if (buf != "") { std::cout << buf << std::endl; // STDOUT } } } } int main(int argc, char** argv) { std::string filename; if (argc > 1) { std::cout << argv[1] << std::endl; filename = argv[1]; } bool start = CreateAnonymousPipes(filename); // Windowed app start while (start) { Sleep(1); ReceiveChild(); } return 0; } Quote Link to comment Share on other sites More sharing options...
Josh Posted March 27, 2017 Author Share Posted March 27, 2017 This is not critical but I wanted to make sure there was no way to do this before I write up my blog. Thanks for the info. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Einlander Posted March 27, 2017 Share Posted March 27, 2017 Would this help? http://stackoverflow.com/questions/191842/how-do-i-get-console-output-in-c-with-a-windows-program And further reading: https://www.gamedev.net/topic/509479-routing-stdout-to-windowconsole/?whichpage=1#3320937 Sadly I am not a c++ guy so I cant be much help here. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.