Great Doctor

Doctor (to patient): "You are ill and need a quiet life. I shall prescribe you a sleeping pill, but give it to your wife."

Waitress: "Would you like some black coffee?"

Customer: "What other colours do you have?"

Ha Ha Ha

SonSon: "Mummy, does God use our bathroom?"

Mother Mother: "No darling"

SonSon: "Well, every morning daddy bangs on the door and shouts, 'Oh God, are you still in there?'"

Young man: "I have come to ask for your daughter's hand."

Father: "You will have to take all of her, or it is no deal."


Chapter 2

The .EXE Solution


In this chapter, you will learn how to invoke the DOS command interpreter file from a C program. The source code needed for this chapter is stored in the examples\Chapter2 directory. The "Chapter2" directory contains the following files:


Listing 2.1 Execute.cpp (Complete code)

//The #include directive treats
//text in the file specified by
//filename as if it appeared in the
//current file.
#include <alloc.h>
#include <process.h>
#include <stdio.h>

//The #define directive defines a macro.
#define MAIN_CLASS "MyFrame.jar"

int main()

	//malloc() allocates a block of size
	//bytes from the memory heap. 
	char* cmdline = (char*)malloc(1024 );
	//sends formatted output to a string
	sprintf(cmdline, "java.exe -jar %s", MAIN_CLASS );

	//system() invokes the DOS 
	//command interpreter
	system( cmdline );

	//deallocate the memory
	free (cmdline);

	return 0;
Contents         Top                              Move to the preceding page Move to the next page
© 2001 All rights reserved