Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
2 registered members (juanex, AndrewAMD), 988 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
windows cmd interaction #345293
10/24/10 20:49
10/24/10 20:49
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline OP
Expert
Germanunkol  Offline 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
M
muffel Offline
Member
muffel  Offline
Member
M

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 Offline OP
Expert
Germanunkol  Offline 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: Germanunkol] #345341
10/25/10 15:01
10/25/10 15:01
Joined: Jul 2000
Posts: 27,935
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,935
Frankfurt
I have never used AllocConsole or other Console functions, so I have no experience with sending text to a certain console, if this is possible at all. But use Google - probably you can find this information on other programmer forums in the Internet.

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 Offline OP
Expert
Germanunkol  Offline 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 Offline
Expert
WretchedSid  Offline
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: WretchedSid] #345409
10/25/10 22:44
10/25/10 22:44
Joined: Sep 2003
Posts: 9,859
F
FBL Offline
Senior Expert
FBL  Offline
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
Lite-C does not support fprintf natively. But maybe there's a change to get it to work using stdlib.

Re: windows cmd interaction [Re: FBL] #345415
10/25/10 23:59
10/25/10 23:59
Joined: Oct 2004
Posts: 897
Lgh
rojart Offline
User
rojart  Offline
User

Joined: Oct 2004
Posts: 897
Lgh


Regards, Robert

Quote
Everything should be made as simple as possible, but not one bit simpler.
by Albert Einstein

PhysX Preview of Cloth, Fluid and Soft Body

A8.47.1P
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 Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Originally Posted By: Firoball
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
M
muffel Offline
Member
muffel  Offline
Member
M

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:
Click to reveal..

console.h
Code:
/// 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
Code:
///////////////////////////////
#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.
Page 1 of 2 1 2

Moderated by  old_bill, Tobias 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1