|
2 registered members (juanex, AndrewAMD),
988
guests, and 8
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
windows cmd interaction
#345293
10/24/10 20:49
10/24/10 20:49
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
OP
Expert
|
OP
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
Hello,
For creating a dedicated server, we would like to have all output/input written to/read from the console that started the published .exe. Making acknex not display anything works well, and I managed to make acknex print to a console it created using AllocConsole. But what I want to do is print back into the cmd.exe that called the game in the first place, and AllocConsole prints to a new console. This is important because we want people to be able to control the dedicated server from another computer, using the console.
Is there a way, for example by setting stdout to point to the calling console?
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: windows cmd interaction
[Re: Germanunkol]
#345295
10/24/10 21:01
10/24/10 21:01
|
Joined: Oct 2009
Posts: 149 Germany
muffel
Member
|
Member
Joined: Oct 2009
Posts: 149
Germany
|
Whats about GetStdHandle and ReadConsole. I believe the using is similiar to the other direction you got working. Tip: Learn how to work with the win32-Documentation. Some look-ups and i got the knowlegde for this suggestion(right word: vorschlag). EDIT: hope i didnt missunderstand you. i thought that the user can type something into the console and your first programm gets this Input. muffel
Last edited by muffel; 10/24/10 21:05.
|
|
|
Re: windows cmd interaction
[Re: muffel]
#345296
10/24/10 21:15
10/24/10 21:15
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
OP
Expert
|
OP
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
I tried GetStdHandle... and yeah, I've been reading that msdn stuff all night. No luck yet... Thanks though...
Last edited by Germanunkol; 10/24/10 21:15.
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: windows cmd interaction
[Re: jcl]
#345398
10/25/10 20:36
10/25/10 20:36
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
OP
Expert
|
OP
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
My problem is that what I find from google is that printf is supposed to write back to the console, but printf is caught by the acknex startup window. Do you know if acknex redirects "STDIN" and "STDOUT"? Because from what I gather, by default, these are set to the calling console. But I might be wrong.
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: windows cmd interaction
[Re: Germanunkol]
#345399
10/25/10 20:46
10/25/10 20:46
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
You can always use fprintf() to write directly into a file.
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: windows cmd interaction
[Re: FBL]
#345415
10/25/10 23:59
10/25/10 23:59
|
Joined: Oct 2004
Posts: 897 Lgh
rojart
User
|
User
Joined: Oct 2004
Posts: 897
Lgh
|
|
|
|
Re: windows cmd interaction
[Re: FBL]
#345428
10/26/10 08:10
10/26/10 08:10
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
Lite-C does not support fprintf natively. What a shame =/
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: windows cmd interaction
[Re: WretchedSid]
#345436
10/26/10 09:01
10/26/10 09:01
|
Joined: Oct 2009
Posts: 149 Germany
muffel
Member
|
Member
Joined: Oct 2009
Posts: 149
Germany
|
Don't know your problem with this Topic. I got it to run a little bit. I required 4 function from the windows Api: -AllocConsole -GetStdHandle this one twice for in and output -WriteConsole writing into the console -ReadConsole reading from the console Sadly i had some problems with the chars. but i could write something to the console and read something from the console. If you want this running without stopping the game. I think you must put this into an extra thread( the read-funktion returns only if in the console Enter is pressed) I think you want to see my solution. Here it is: console.h
/// loading some required functions not defined in windows.h
BOOL WINAPI WriteConsole( HANDLE , const VOID* , DWORD , LPDWORD , LPVOID );
#define PRAGMA_API WriteConsole;kernel32!WriteConsoleA
BOOL WINAPI ReadConsole(HANDLE ,LPVOID ,DWORD ,LPDWORD ,LPVOID );
#define PRAGMA_API ReadConsole;kernel32!ReadConsoleA
console.c
///////////////////////////////
#include <acknex.h>
#include <windows.h>
#include "console.h"
///////////////////////////////
#define PRAGMA_POINTER
HANDLE c_out = 0;
HANDLE c_in = 0;
function main()
{
video_screen = 0;
wait(1);
/// allocating console
AllocConsole();
SetConsoleTitle("Acknex Console");
/// prepare in output
c_out = GetStdHandle( STD_OUTPUT_HANDLE );
c_in = GetStdHandle( STD_INPUT_HANDLE );
if( !c_out ) printf( "no output" );
if( !c_in ) printf( "no input" );
DWORD written = 0;
DWORD read = 0;
char* in_buffer;
char prep_buff[128];
WriteConsole( c_out, "Console Entered\n", 16 , &written , NULL );
/// polling input
while(!key_esc)
{
ReadConsole( c_in , in_buffer , 128 , &read , NULL );
if( read > 0 )
{
memset((void*)&prep_buff,0,sizeof(prep_buff)); // safety for nulling the prepbuffer
DWORD i;
for( i = 0 ; i < 128 ; i++ )
{
if( i < read )
{
prep_buff[i] = in_buffer[i]; // copy chars
}
else
{
prep_buff[i] = 0; // fill the rest with 0
}
}
/// print to acknex
printf("Eingabe: ");
printf(prep_buff);
/// print to console
WriteConsole( c_out, "Eingabe: ", 9 , &written , NULL );
WriteConsole( c_out, in_buffer, read , &written , NULL ); /// works great
//WriteConsole( c_out, prep_buff, read , &written , NULL ); /// for some stupid unknown reason prints nonsesnse
WriteConsole( c_out, "\n", 1 , &written , NULL );
}
wait(1); // let acknex do its stuff.
}
FreeConsole();
sys_exit(NULL);
}
Hope my Code could help anybody. EDIT: I should read the hole threads including the links. So someone was faster with the code which is i think also nicer(at least i haven't copy and pasted the code from somewhere) muffel
Last edited by muffel; 10/26/10 09:08.
|
|
|
|