Where did my console output go?

C

CarlosMB

Hello,

I am writing code that uses a DLL which is supposed to print to
console
some useful information but for some reason it is not doing so. The
environment
is a bit complex to explain but here it goes:

- I am using a C library called SYMPHONY, which I compiled myself.
When using that
library in an standard console application I get the console output
right.

- I wrote a wrapper for the library in C to hook it into Matlab via
mex-files (which
are C files compiled to DLLs, but with a different name)

- This wrapper altogether with the library is used in a Matlab
program. From inside
Matlab the SYMPHONY output doesn't show up.

- This Matlab program is compiled into a .NET component which when
used by
a console application in Visual Studio shows all the information i was
missing in
the previous step.

Since I am not understanding what is going on right here I would like
to write
all the information that sometimes appears in the console (and
sometimes not)
to a file, but without the need to modify the SYMPHONY library that I
built in
the first step.

Is there anything in the C standard library that can help me with
this?

Thanks in advance,

Carlos Martínez
 
J

jacob navia

CarlosMB said:
Hello,

I am writing code that uses a DLL which is supposed to print to
console
some useful information but for some reason it is not doing so. The
environment
is a bit complex to explain but here it goes:

- I am using a C library called SYMPHONY, which I compiled myself.
When using that
library in an standard console application I get the console output
right.

- I wrote a wrapper for the library in C to hook it into Matlab via
mex-files (which
are C files compiled to DLLs, but with a different name)

- This wrapper altogether with the library is used in a Matlab
program. From inside
Matlab the SYMPHONY output doesn't show up.

- This Matlab program is compiled into a .NET component which when
used by
a console application in Visual Studio shows all the information i was
missing in
the previous step.

Since I am not understanding what is going on right here I would like
to write
all the information that sometimes appears in the console (and
sometimes not)
to a file, but without the need to modify the SYMPHONY library that I
built in
the first step.

Is there anything in the C standard library that can help me with
this?

Thanks in advance,

Carlos Martínez


Hola Carlos

Answer in Spanish so the pedants in this group do not get it!

Lo mejor que puedes hacer es llamar la funcion

AllocConsole();

cuando comienzas tu programa. Esto va FORZAR la existencia de una
consola. Probablemente sabes ya que programas utilizando solamente
windows no crean una consola.
 
N

Nick Keighley

CarlosMB wrote:









Hola Carlos

Answer in Spanish so the pedants in this group do not get it!

Lo mejor que puedes hacer es llamar la funcion

AllocConsole();

cuando comienzas tu programa. Esto va FORZAR la existencia de una
consola. Probablemente sabes ya que programas utilizando solamente
windows no crean una consola.

comp.lang.c is an English language news group and posting should
be restricted to that language.


;-)
 
J

James Kuyper

No. That kind of thing is in the domain of your windowing system, not
the C standard.
Hola Carlos

Answer in Spanish so the pedants in this group do not get it!

That's ridiculous. You're assuming he can read it, just because he's got
a Hispanic name, and you're assuming that we can't read it just because
-- it's not actually clear why you've made that assumption, but I'm at
least one counterexample. From the message he sent, the only language
you can be certain that he is fluent in is English, and he seems fairly
fluent in it.
Lo mejor que puedes hacer es llamar la funcion

AllocConsole();

He was very specific about this: he asked for a C standard library
function. AllocConsole() is not in the C standard library. You did not
answer the question he asked, you answered a different question of your
own devising.
cuando comienzas tu programa. Esto va FORZAR la existencia de una
consola. Probablemente sabes ya que programas utilizando solamente
windows no crean una consola.

Even if he had asked for a Windows-specific answer, rather than a C
standard library answer, you would still have done him a better service
by redirecting his inquiry to a forum devoted to the kind of system he's
using. In that forum, he'd have a better chance than he has here of
hearing from someone else whether or not your advice makes any sense.
 
C

CBFalconer

Nick said:
.... snip ...


comp.lang.c is an English language news group and posting should
be restricted to that language.

No it isn't. However it is a public newsgroup, and private
communications should be done via e-mail. Attempts to use it for
private communications is a very bad error by Mr Navia. Public
communications are much more likely to be understood by all when
done in English, or a reasonable approximation thereto.
 
B

Bartc

CarlosMB said:
Hello,

I am writing code that uses a DLL which is supposed to print to
console
some useful information but for some reason it is not doing so. The
environment
is a bit complex to explain but here it goes:

- I am using a C library called SYMPHONY, which I compiled myself.
When using that
library in an standard console application I get the console output
right.

- I wrote a wrapper for the library in C to hook it into Matlab via
mex-files (which
are C files compiled to DLLs, but with a different name)

- This wrapper altogether with the library is used in a Matlab
program. From inside
Matlab the SYMPHONY output doesn't show up.

My (limited) experience is that the presence or otherwise of a console
window depends on the link options used (eg console or windows).

If you don't have control of this, then Jacob's AllocConsole() idea might be
work (for all I know, all the link option does might be to call this at
startup).

However when I tried this in an experiment, I couldn't get any output on the
console, not with printf() anyway. And none of this is standard C either.
 
H

Herbert Kleebauer

CarlosMB said:
Hello,

I am writing code that uses a DLL which is supposed to print to
console
some useful information but for some reason it is not doing so. The
environment

Try:

#ifdef debug
void init_stdout()
{int hCrt;
FILE *hf;

AllocConsole();
hCrt = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE),_O_TEXT);
hf = _fdopen( hCrt, "w" );
*stdout = *hf;
setvbuf( stdout, NULL, _IONBF, 0 );
printf("stdout is working!!!\n");

hCrt = _open_osfhandle((long)GetStdHandle(STD_INPUT_HANDLE),_O_TEXT);
hf = _fdopen( hCrt, "r" );
*stdin = *hf;
setvbuf( stdin, NULL, _IONBF, 0 );

printf("type a character followed by a <CR> to test stdin: ");
/*printf("\nYou typed: %c\n",getchar()); */
}
#endif
 
D

dj3vande

CarlosMB said:
- I am using a C library called SYMPHONY, which I compiled myself.
When using that
library in an standard console application I get the console output
right.

That seems to indicate that the library is writing its output to
stdout. (Either that or it's playing Windows-specific games with the
output, which puts your problem well outside the scope of comp.lang.c.)

This is not exactly a good thing for a library to do, since it's likely
to, at some point (like in your project), be used in a program where
stdout isn't the right place for output to go.

- I wrote a wrapper for the library in C to hook it into Matlab via
mex-files (which
are C files compiled to DLLs, but with a different name)

- This wrapper altogether with the library is used in a Matlab
program. From inside
Matlab the SYMPHONY output doesn't show up.

Check the SYMPHONY documentation to see if you can find a way to have
the output go through a function you provide instead of just being
written to stdout. If you can do that, you can just have your mex-file
wrapper send it through the appropriate Matlab output function[1]
instead of to stdout. (Applications that have stdout attached can keep
just using the default.)

If the library doesn't support this and insists on always sending its
output to stdout, there's not much you can do without either modifying
the library or convincing the maintainers of the library to modify it
for you.


[Snip description of running under Matlab with a console window open -
I believe the Windows stdio library will always output to the process's
console window if there is one, which is consistent with the described
behavior]

Is there anything in the C standard library that can help me with
this?

Not if you can't redirect the output through something other than the
standard library's stdio functions and need portable C code.

You may be able to persuade the stdio library to create an output
stream that gives you the data that's written to it. If you can do
this, and if you can persuade the library you're using to write to such
a stream (you may need to modify stdout and/or stderr to accomplish
this), you can capture the output and send it somewhere appropriate.
There is no portable way to do this, but if you're willing to tie your
code down to a particular platform, you may be able to find something
that will work.


dave


[1] I happen to have the Matlab External Interfaces manual on my
bookshelf, and it indicates that mexPrintf is probably the function
you want for this. But a Matlab newsgroup would be a much better
place to discuss Matlab's foreign code support.
 
R

Richard Bos

Hola Carlos

Answer in Spanish so the pedants in this group do not get it!

So let's get this straight. You're going for the triple whammy here.
You're an idiot, you're dishonest...
Lo mejor que puedes hacer es llamar la funcion

AllocConsole();

cuando comienzas tu programa.

...._and_ you're wrong. Well done.

Richard
 
J

jacob navia

Richard said:
You're an idiot, you're dishonest...


So, you think you can insult anyone like that ?

You, and the other cowards here, are only "strong" when
insulting. Then, you feel good.

Unable to argument anything the only thing your feeble brain is able
to do is that: insulting.
 
C

CBFalconer

jacob said:
So, you think you can insult anyone like that ?

You, and the other cowards here, are only "strong" when insulting.
Then, you feel good. Unable to argument anything the only thing
your feeble brain is able to do is that: insulting.

You ingeniously trimmed away the insults and Usenet misuse you
supplied. I have attempted to restore them, and I think I got the
attributions correct. Just to establish exactly who is misusing
the Usenet system. And who is insulting whom.
 
J

jacob navia

CBFalconer said:
You ingeniously trimmed away the insults and Usenet misuse you
supplied.

Lying again. I did notinsult anyone. At most I tried to avoid
the pedants in this group.


I have attempted to restore them, and I think I got the
attributions correct.

Yes. As anyone can see, I did not insult anyone.
Just to establish exactly who is misusing
the Usenet system. And who is insulting whom.

Exactly. None of the quoted material attributed to me has any insults
like "idiot".
 
V

vippstar

jacob navia said:

"You, and the other cowards here". "Lying again". Both of these are
considered insulting. Also, it is clear from context that you consider the
word "pedants" to be insulting. (Those whom you insult in such a way,
however, are unlikely to be bothered by the word, since to them it simply
means "people who care about getting it right", which is clearly not a
major concern of yours.

You forgot the closing paren ).
:)
 
A

Antoninus Twink

You don't think that calling people cowards and liars counts as
insulting them?

If someone makes a deliberately false statement to try to undermine
another's reputation, is it an insult to call them a liar, or simply a
statement of fact?
(Those whom you insult in such a way, however, are unlikely to be
bothered by the word, since to them it simply means "people who care
about getting it right", which is clearly not a major concern of
yours.

Less than two hours ago, you said on this board:
either put up with him or plonk him, I guess - but picking on people
is just plain wrong.

and here you are carrying on with your nasty, insidiious campaign of
bullying against Jacob. What a despicable little weasel you are.
 
J

jacob navia

One of the many questions asked by people is that even if they write
into standard output, the output doesn't show in the screen. This
happens in windows systems since quite a long time.

To avoid this, you should open a console before outputting anything
into standard output. You do this with

void AllocConsole(void);

When you do not want to use the console any more (and you do not
want the ugly black window hanging around) you just do:
BOOL WINAPI FreeConsole(void);

The operating system opens up a console for all programs that
have the bit of "console application" set in the executable. That is
why you do NOT needto open a console for those programs. Programs
that need this are only programs that were compiled with the
"subsystem windows" bit set.

-------------------------------------------------------------------

You find this off topic for clc?

You can go to hell. There, you can complain to the boss.

You find me obnoxious?

You can go to heaven and complain there to the boss.
 
J

jacob navia

Antoninus said:
If someone makes a deliberately false statement to try to undermine
another's reputation, is it an insult to call them a liar, or simply a
statement of fact?

I did not insult anyone.

Boss insulted me treating me of idiot.

I told him he was a coward.

Falconer quoted the conversation saying I was the one
insulting.

Heathfield starts after Falconer continuing the story that
it is me that is insulting people.
 
B

Ben Bacarisse

This supposed FAQ intrigues me, though I may regret asking about it.

jacob navia said:
One of the many questions asked by people is that even if they write
into standard output, the output doesn't show in the screen. This
happens in windows systems since quite a long time.

To avoid this, you should open a console before outputting anything
into standard output. You do this with

void AllocConsole(void);

Is there not a way do get the same effect without using non-portable
constructs? I don't use Windows so I am often amazed at what people
say is needed to get X to work or Y to do the "usual" thing, but is it
really that odd a system? Is there no way to run a standard C program
that reads stdin and writes stdout in a usable way?

You find this off topic for clc?

Personally, no. If it means that standard C is not a usable option
for such simple programs, then I think the warning is topical.
Alternatives are not hard to come by if you are a beginner learning C.
 
J

James Kuyper

CBFalconer said:
You ingeniously trimmed away the insults and Usenet misuse you
supplied. I have attempted to restore them, and I think I got the
attributions correct. Just to establish exactly who is misusing
the Usenet system. And who is insulting whom.

I most emphatically deny that the term "pedant", as used by jacob navia,
counts as an insult. Whether or not he intends it as such, the way he
uses it is as a term that describes anyone who cares more about the
accuracy of what he's saying than jacob does, and that's a pretty low
standard to measure pedantry by.
 
S

s0suk3

(Those whom you insult in such a way,
however, are unlikely to be bothered by the word, since to them it simply
means "people who care about getting it right",

But pedants don't usually get things right (alas, they don't usually
get things even *done*; they just know how to criticize :)

Sebastian
 
J

jacob navia

Ben said:
This supposed FAQ intrigues me, though I may regret asking about it.



Is there not a way do get the same effect without using non-portable
constructs?

Yes, compile your program as a console program, and windows
will open a console window for you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top