trm_run_program()

Purpose

Runs another program

Old name

#define _run_prog trm_run_program

Syntax

int trm_run_program(const char *command, int batch, int flags);

Parameters

char* name

Name of program to run

 

int batch

If the program cannot be executed directly and this parameter is TRUE the terminal manager uses the shell to execute the command. On Windows a value of 2 will cause the ShellExecute() function to be used to execute the command. In this case command wil normally just be a document name, and the program to be executed will be selected based on the registry information. This is useful where you want to invoke the user's preferred web browser to open a web page, for example.

 

int flags

This can contain a combination of the TR_ flags in dp4uiapi.h. Not all the flags are meaningful on all platforms. For example the TR_NOWAIT parameter is not supported on MS-DOS.

Description

The trm_run_program() function is used to run another program.

Return values

Returns TRUE if the named program is successfully called, otherwise FALSE. Exit code information for the called program is not available from trm_run_program(). See also trm_run_program_ex()

Example

/*
C Functions Reference Manual
----------------------------
Filename: TRM_RUN_.C
Example: trm_run_program
Purpose: program uses DOS's copy command to copy a
file.
*/

#include "dp4.h"
#include "trm_run_.h"
/* generate this file by running LIBMAKE */

/*
#db salesord
#c
#end
*/

/* prototypes */
void name_inner(int,int*);
void do_copy(void);
/* variables */
static char exis_file[65];
static char new_file[65];
void process()
{
trm_read_user();
/* only required if using Microsoft C: a bug in
the linker causes an unresolved external error
in the DP4 library */
map_datamap(1);
/* put up header map */
map_datamap(2);
/* put up input map */
if (map_get_inputs(2,1,name_inner,NO_DISP|RETAIN)
== 0)
do_copy();
}

static void zero_term(char* name,int max_len)
{
register int i = 0;
while (*name != ' ' && *name != NULL_CHAR &&
i < max_len)
{
i++;
name++;
}
*name = '\0';
}

void do_copy()
{
char command[156] = "copy ";
strcat(command,exis_file);
strcat(command, " ");
strcat(command,new_file);
/* move cursor */
trm_cursor(15,1);
trm_refresh();
/* call copy command */
if (!trm_run_program(command,TRUE,FALSE))
{
map_draw(3,SCROLL);
trm_refresh();
}
}

void name_inner(int m, int* f)
{
int k = *f;
switch (*f)
{
case 1: /* file to copy */
if (inpm_c(exis_file))
break;
zero_term(exis_file,sizeof(exis_file) - 1);
if (tf_check(exis_file) != 1)
{
map_remark(5);
/* put up bad file name remark */
*f = k;
}
break;
case 2:
if (inpm_c(new_file))
break;
zero_term(new_file,sizeof(new_file) - 1);
/* go round again if all blanks */
if (new_file[0] == '\0')
*f = k;
break;
default:
inpm_omit();
break;
}
}