First post, by emendelson
EDIT: I figured out how to do this by stealing some code from debug.cpp.
I probably shouldn't be messing with things I don't understand, but I got the idea of adding a START command to DOSBox so that I could run a Windows command from the DOSBox command line. I'm not sure why I would want to do this, but I thought I might learn something by trying it. So, by stealing code that I don't understand, I put together this for dos_programs.cpp:
First, add these lines above all the other Includes:
#include "windows.h"
#include "Shellapi.h"
#include "shell.h"
Next, add this among the existing code for commands:
class START : public Program {
public:
void Run(void);
};
void START::Run(void) {
Bit16u rate=0,delay=0,mode;
//Hack To allow long commandlines
ChangeToLongCmd();
/* Parse the command line */
if (!cmd->FindCommand(1,temp_line) || temp_line=="/?") {
WriteOut(MSG_Get("PROGRAM_START_USAGE"));
return;
}
else if (cmd->FindCommand(1,temp_line)) {
char filename[128];
char args[256];
cmd->FindCommand(1,temp_line);
safe_strncpy(filename,temp_line.c_str(),128);
// Read commandline
Bit16u i =2;
args[0] = 0;
for (;cmd->FindCommand(i++,temp_line)==true;) {
strncat(args,temp_line.c_str(),256);
strncat(args," ",256);
}
ShellExecute(0, "open", filename, args, NULL, SW_SHOWNORMAL);
return;
}
}
Then add something like this to the section of the file that has the MSG_Add strings:
MSG_Add("PROGRAM_START_USAGE","\033[34;1mSTART\033[0m Windows_command [arguments]\n");
Then add to this the list of PROGRAMS_MakeFile entries near the foot of the file:
PROGRAMS_MakeFile("START.COM", START_ProgramStart);
Finally, add to shell.h a line reading:
void CMD_START(char * args);
As far as I can tell, this makes it possible to run commands like this from the DOSBox command line:
start notepad.exe c:\mydir\mytext.txt
start calc.exe
start http://www.vogons.org
The third one opens the web page in the default browser.
I hope someone else might find this useful.