Detabbed
[AROS.git] / rom / dos / execute.c
bloba62a9c80057cacaf0b673482b1f9812be507dd8f
1 /*
2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Execute a CLI command
6 Lang: English
7 */
9 #include <aros/debug.h>
10 #include <dos/dosextens.h>
11 #include <utility/tagitem.h>
13 #include "dos_intern.h"
15 /*****************************************************************************
17 NAME */
18 #include <proto/dos.h>
20 AROS_LH3(BOOL, Execute,
22 /* SYNOPSIS */
23 AROS_LHA(CONST_STRPTR, string, D1),
24 AROS_LHA(BPTR , input , D2),
25 AROS_LHA(BPTR , output, D3),
27 /* LOCATION */
28 struct DosLibrary *, DOSBase, 37, Dos)
30 /* FUNCTION
32 Execute a CLI command specified in 'string'. This string may contain
33 features you may use on the shell commandline like redirection using >,
34 < or >>. Execute() doesn't return until the command(s) that should be
35 executed are finished.
36 If 'input' is not NULL, more commands will be read from this stream
37 until end of file is reached. 'output' will be used as the output stream
38 of the commands (if output is not redirected). If 'output' is NULL the
39 current window is used for output -- note that programs run from the
40 Workbench doesn't normally have a current window.
42 INPUTS
44 string -- pointer to a NULL-terminated string with commands
45 (may be NULL)
46 input -- stream to use as input (may be NULL)
47 output -- stream to use as output (may be NULL)
49 RESULT
51 Boolean telling whether Execute() could find and start the specified
52 command(s). (This is NOT the return code of the command(s).)
54 NOTES
56 EXAMPLE
58 BUGS
60 SEE ALSO
62 SystemTagList()
64 INTERNALS
66 To get the right result, the function ExecCommand() (used by both Execute()
67 and SystemTagList()) uses NP_Synchronous to wait for the commands to
68 finish. This is not the way AmigaOS does it as NP_Synchronous is not
69 implemented (but defined).
71 *****************************************************************************/
73 AROS_LIBFUNC_INIT
75 LONG result;
76 struct TagItem tags[] =
78 { SYS_Background, TRUE },
79 { SYS_Asynch, FALSE },
80 { SYS_Input, (IPTR)input },
81 { SYS_Output, (IPTR)output },
82 { SYS_Error, (IPTR)NULL },
83 { TAG_DONE, 0 }
86 D(bug("[Execute] input = %p, output = %p, cmd = \"%s\"\n", input, output, string));
88 /* Check for the special cases where we want a new
89 * interactive shell.
91 if ((!string || string[0] == 0) && IsInteractive(input) && output == BNULL)
92 tags[0].ti_Data = FALSE;
94 if ((!string || string[0] == 0) && input == BNULL && output == BNULL)
95 string = "Run NewShell";
97 result = SystemTagList(string, tags);
99 if(result == 0)
100 return DOSTRUE;
101 else
102 return DOSFALSE;
104 AROS_LIBFUNC_EXIT
105 } /* Execute */