New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / workbench / c / shellcommands / Run.c
blob048fac0d381ebf40ab399f589e3eaff9479341f3
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /******************************************************************************
11 NAME
13 Run
15 SYNOPSIS
17 COMMAND/F
19 LOCATION
21 Workbench:C
23 FUNCTION
25 Run a program, that is start a program as a background process.
26 That means it doesn't take over the parent shell.
28 INPUTS
30 COMMAND -- the program to run together with its arguments
32 RESULT
34 NOTES
36 To make it possible to close the current shell, redirect the output
37 using
39 Run >NIL: program arguments
41 EXAMPLE
43 BUGS
45 SEE ALSO
47 INTERNALS
49 HISTORY
51 ******************************************************************************/
53 #include <exec/memory.h>
54 #include <proto/exec.h>
55 #include <dos/filesystem.h>
56 #include <dos/dosextens.h>
57 #include <dos/dostags.h>
58 #include <proto/dos.h>
59 #include <utility/tagitem.h>
61 #include <aros/shcommands.h>
63 AROS_SH1(Run, 41.2,
64 AROS_SHA(STRPTR, ,COMMAND,/F,NULL))
66 AROS_SHCOMMAND_INIT
68 struct CommandLineInterface *cli = Cli();
69 BPTR cis = NULL, cos = NULL, ces = NULL;
70 LONG CliNum;
73 if (cli)
75 BPTR toclone, olddir;
77 if (IsInteractive(Input()))
78 toclone = Input();
79 else
80 toclone = cli->cli_StandardInput;
82 olddir = CurrentDir(toclone);
83 cis = Open("", FMF_READ);
84 CurrentDir(olddir);
86 if (IsInteractive(Output()))
87 toclone = Output();
88 else
89 toclone = cli->cli_StandardOutput;
91 olddir = CurrentDir(toclone);
92 cos = Open("", FMF_WRITE);
93 CurrentDir(olddir);
95 /* This is sort of a hack, needed because the original AmigaOS shell didn't allow
96 Error() redirection, so all the scripts written so far assume that only Input() and
97 Output() require to be redirected in order to not block the parent console */
98 if (Error() != cli->cli_StandardError && IsInteractive(Error()))
100 toclone = Error();
102 olddir = CurrentDir(toclone);
103 ces = Open("", FMF_WRITE);
104 CurrentDir(olddir);
109 struct TagItem tags[] =
111 { SYS_Input, (IPTR)cis },
112 { SYS_Output, (IPTR)cos },
113 { SYS_Error, (IPTR)ces },
114 { SYS_Background, TRUE },
115 { SYS_Asynch, TRUE },
116 { SYS_CliNumPtr, (IPTR)&CliNum },
117 { SYS_UserShell, TRUE },
118 { TAG_DONE, 0 }
122 if (SystemTagList(SHArg(COMMAND), tags) == -1)
124 PrintFault(IoErr(), "Run");
125 Close(cis);
126 Close(cos);
127 Close(ces);
129 return RETURN_FAIL;
134 IPTR data[1] = { (IPTR)CliNum };
135 VPrintf("[CLI %ld]\n", data);
138 return RETURN_OK;
140 AROS_SHCOMMAND_EXIT