1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
*/
#define import_spp
#define import_libc
#define import_stdio
#include <iraf.h>
#include "errs.h"
/* CLSYSTEM -- Run a host system command and try to arrange for its standard
* output and standard error output to go where our t_stdout is going; this
* will let us redirect its output and use it with pipes..
*/
void
clsystem (
char *cmd, /* command to be executed */
FILE *taskout, /* stdout of task */
FILE *taskerr /* stderr of task */
)
{
register char *ip;
register int ch;
char outfile[SZ_PATHNAME], errfile[SZ_PATHNAME];
FILE *fp;
/* Ignore null commands.
*/
for (ip=cmd; (*ip == ' ' || *ip == '\t'); ip++)
;
if (*ip == EOS)
return;
/* Run command with output redirected into temporary files.
* This is done only if the output is redirected.
*/
outfile[0] = EOS;
errfile[0] = EOS;
if (taskout && taskout != stdout)
c_mktemp ("tmp$tso", outfile, SZ_PATHNAME);
if (taskerr == taskout)
strcpy (errfile, outfile);
else if (taskerr && taskerr != stderr)
c_mktemp ("tmp$tse", errfile, SZ_PATHNAME);
c_oscmd (cmd, "", outfile, errfile);
/* Copy spooled output, if any, to the error streams of the current
* task.
*/
if (outfile[0] != EOS)
if ((fp = fopen (outfile, "r")) != NULL) {
while ((ch = fgetc (fp)) != EOF)
fputc (ch, taskout);
fclose (fp);
c_delete (outfile);
}
if (errfile[0] != EOS && taskerr != taskout)
if ((fp = fopen (errfile, "r")) != NULL) {
while ((ch = fgetc (fp)) != EOF)
fputc (ch, taskerr);
fclose (fp);
c_delete (errfile);
}
}
|