0

I want to create a simple handler for my game server. It will read the console directly and take any action i want. BUT! I can't pass the output from the server to my exe or txt.

ping google.com > ping.log

It works fine, everything will be logged in my log file. Also I created an exe, that can read the output data this way:

ping google.com | my.exe

It also works fine, my exe's content is:

#include <iostream>
#include <windows.h>

using namespace std;

int main() {
    string input = "";
    while(cin) {
        getline(cin, input);
        cout << input << endl;
    };
    system("pause");
}

It shows everything line by line.

The problem is with the jampded.exe. If I start it with a batch file, it has output in the console window, but I can not pass this for my log file, or my.exe. I have no idea.

I put cout-s in my code, so it shows it is stucking in the while loop. getline waits for cin, but nothing passed.. But why?

Iburidu
  • 450
  • 2
  • 5
  • 15
  • it is the same, jampded can't send output for some reason.. but there is output in the console, if i double click that, so there must be output – Iburidu Jun 12 '13 at 12:02

2 Answers2

0

Your program may use stderr to output data.

Try to replace jampded.exe | yourprogram.exe by jampded.exe 2| yourprogram.exe

Matthieu Rouget
  • 3,289
  • 18
  • 23
  • nothing, i tried with txt also with 0> 1> 2> 3> 4> 5> 6> 7> 8> 9>, and only the second has ^C, which is the close i guess – Iburidu Jun 12 '13 at 11:49
0

I am unfamiliar with jampded, but normally, a server will output some start messages to the console, and then detach itself from the console input/output, so it can run in the background. Any further messages may be written to a log file.

It is possible that you can start jampded with command line or configuration file options to keep writing to the console. Or you could read the log file. (For which I normally use "tail.exe -f" from the gnuwin32 file utils.)

A quick search on google also shows that there is a non-dedicated server version called jamp.exe. For testing purposes it may offer more flexibility to capture the output.

Jer
  • 391
  • 1
  • 5
  • it writes everything directly to my batch file, but I cannot write anything to the log. jamp exe (jedi academy multiplay) is graphic program, it is the game and i cant start it in console. – Iburidu Jun 12 '13 at 14:55
  • When you stop the server, is all the output still in your console screen? – Jer Jun 12 '13 at 15:27
  • Have you tried to put the redirect command in the batch file, after the jampded.exe? If not, I would try that first. If that doesn't work, it's possible that it created its own Console buffer, and that you have to play around with [AttachConsole](http://msdn.microsoft.com/en-us/library/windows/desktop/ms681952(v=vs.85).aspx) to access the content. – Jer Jun 12 '13 at 16:42
  • what is redirect command?:) you can be right, i guess it doesnt write to standard input/output anything, thats why i cant catch data. – Iburidu Jun 13 '13 at 09:04
  • The | and > redirect the output. Just to make sure that the batchfile isn't messing things up, you could use them directly after jampded.exe. I still think that reading jampded's log file is the best option. – Jer Jun 13 '13 at 10:29