It is advertised all over the place that "start" will execute a command
in the background on a Windows machine. However, as a remote host
command from k95 'start' appears to not work like that.

On a Win2k box running purchased K95 2.1.3 talking to Linux with
C-Kermit 8.0.211 over 3-wire RS232.

k95.exe is started via shortcut in Administrator's Startup folder. It's
script is:

cd \my_dir
set line com3
set speed 115200
set flow-control none
set carrier-watch off
set server keepalive on
enable host remote
server
quit

Linux side is invoked on the shell with:

kermit -B -0 -8 -i -Q -C "set line /dev/ttyS0,set speed 115200,set
flow-control none,set carrier-watch off,remote host start cmd,if success
{ exit 0 }, exit 1"

Rather than immediately return, k95 server waits for cmd.exe to exit.
During that time it continues to update the transfer display.

I wrote a simple replacement for "start" that really does execute the
command in the background. It looks like DETACHED_PROCESS is the magic
that immediately returns control to the parent. Using this, I can do
"remote host my_start cmd.exe /c start batch_file.bat" and I'll see the
batch file begin executing in a fresh console while k95 shows the output
of my program ("CHILD PID") and waits for more commands.

I think ultimately we should blame Microsoft here. Either 'start'
doesn't set DETACHED_PROCESS (why not?) or it's not supposed to and the
documentation is wrong.

However, it might be interesting to users if k95 sees that the first
parameter to "remote host" is 'start' and sets DETACHED_PROCESS on its
own while spawning the command.


----sample code below----


#include
#include
#include

int main(int argc, char * argv[]) {
char cmdline[1024];
int i;
STARTUPINFO si;
PROCESS_INFORMATION pi;

if (argc <= 1) {
fprintf(stderr, "No arguments specified!\n");
exit(1);
}

// Build the command line from every other argument
memset(cmdline, 0, sizeof(cmdline));
for (i=1; i sprintf(cmdline + strlen(cmdline), "%s ", argv[i]);
}
// Nix trailing whitespace
cmdline[strlen(cmdline) - 1] = 0;
fprintf(stdout, "COMMAND LINE: \'%s\'\n", cmdline);

ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );

// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line).
cmdline, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
DETACHED_PROCESS, // Creation flags
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION
structure.
) {
fprintf(stderr, "CreateProcess failed!\n");
exit(2);
}

fprintf(stdout, "CHILD PID: %d\n", pi.dwProcessId);

// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return 0;
}