0

I have a C++ console application that returns some kind of things, then, I need to show that in a browser. So I tried to write every console.write from C++ to a .txt file for future PHP reading, but no success because it doesn't write the errors!

Then I tried to use exec('program.exe', $output); at PHP but no success too.. :/

  • Is there another way to do that?
  • Or any function in C++ that writes to a .txt every single thing that shows up in the console?
  • Or some function in another Programming Language that catches everything in the console?
arserbin3
  • 6,010
  • 8
  • 36
  • 52
Juliano Lima
  • 709
  • 3
  • 10
  • 17

2 Answers2

0

You have to understand that cout (standard output) and cerr (standard error output) are two different streams, so probably you forgot to redirect cerr to your text file as well. Here some ideas you can use:

  • Redirect your streams to a file on your code (see How to redirect cin and cout to files?)
  • Redirect the output of any console program from the command line (you don't require to change the code and works on windows and unix / linux) by calling it this way executable.exe > out.txt 2>&1 (see Redirect all output to file)
  • Connect your web application to your console application using TCP sockets (might be an overhead but useful if the application requires some kind of interactive control)
Community
  • 1
  • 1
ButterDog
  • 5,115
  • 6
  • 43
  • 61
  • Trying to use the second method output that to the .txt: Exce‡Æo Sem Tratamento: System.IO.IOException: Identificador inv lido. in System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) in System.IO.__Error.WinIOError() in System.Console.set_CursorVisible(Boolean value) in Butterfly.Program.InitEnvironment() at c:\Users\Administrador\Desktop\Revision 5 - Alpha 3\Butterfly\Program.cs:linha 58 in Butterfly.Program.Main() at c:\Users\Administrador\Desktop\Revision 5 - Alpha 3\Butterfly\Program.cs:line 37 – Juliano Lima Dec 10 '13 at 13:24
  • It'd be easier if you edited your question and added the relevant pieces of code (the code where you call your external application and the lines where the error appears) – ButterDog Dec 10 '13 at 16:30
-1

There are three standard file handles known as stdin, stdout, stderr. Looks like you're only fetching stdout right now. Try to redirect stderr to stdout.

exec('program.exe 2>&1', $output);

(works not only on *nix but also win32).

see also: In the shell, what does " 2>&1 " mean?

Community
  • 1
  • 1
VolkerK
  • 95,432
  • 20
  • 163
  • 226