1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: command.hxx,v $
10 * $Revision: 1.6.40.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
36 #include <tools/stream.hxx>
39 #define TMPNAME "\\command.tmp"
41 #define TMPNAME "/tmp/command.tmp"
44 /** Different types of spawnable programs
48 EXE
, /// programm is a native executable
49 BAT
, /// programm is a DOS-Batch
50 BTM
/// programm is a 4DOS-Batch
53 #define COMMAND_NOTFOUND 0x0001
54 #define COMMAND_TOOBIG 0x0002
55 #define COMMAND_INVALID 0x0004
56 #define COMMAND_NOEXEC 0x0008
57 #define COMMAND_NOMEM 0x0010
58 #define COMMAND_UNKNOWN 0x0020
61 #define COMMAND_SHELL "4nt.exe"
64 #define COMMAND_SHELL "4os2.exe"
67 #define COMMAND_SHELL "csh"
75 friend class ChildProcess
;
83 CommandLine(BOOL bTmpWrite
= FALSE
);
84 CommandLine(const char *, BOOL bTmpWrite
= FALSE
);
85 CommandLine(const CommandLine
&, BOOL bTmpWrite
= FALSE
);
86 virtual ~CommandLine();
90 CommandLine
& operator=(const CommandLine
&);
91 CommandLine
& operator=(const char *);
92 void BuildCommand(const char *);
93 char** GetCommand(void) { return ppArgv
; }
94 void Strtokens(const char *);
98 static ByteString
thePath( "PATH" );
100 /** Declares and spawns a child process.
101 The spawned programm could be a native executable or a schell script.
106 ByteString aCommandLine
;
115 void Initpp( ULONG nCount
, ByteString
&rStr
);
118 /** Creates the process specified without spawning it
119 @param rString specifies the programm or shell scrip
121 CCommand( ByteString
&rString
);
123 /** Creates the process specified without spawning it
124 @param pChar specifies the programm or shell scrip
126 CCommand( const char *pChar
);
128 /** Try to find the given programm in specified path
129 @param sEnv specifies the current search path, defaulted by environment
130 @param sItem specifies the system shell
131 @return the Location (when programm was found)
133 static ByteString
Search( ByteString sEnv
= thePath
,
134 ByteString sItem
= COMMAND_SHELL
);
136 /** Spawns the Process
137 @return 0 when spawned without errors, otherwise a error code
141 ByteString
GetCommandLine_() { return aCommandLine
; }
142 ByteString
GetCommand() { return aCommand
; }
144 char** GetCommandStr() { return ppArgv
; }
147 #define COMMAND_EXECUTE_WINDOW 0x0000001
148 #define COMMAND_EXECUTE_CONSOLE 0x0000002
149 #define COMMAND_EXECUTE_HIDDEN 0x0000004
150 #define COMMAND_EXECUTE_START 0x0000008
151 #define COMMAND_EXECUTE_WAIT 0x0000010
152 #define COMMAND_EXECUTE_REMOTE 0x1000000
154 typedef ULONG CommandBits
;
156 /** Allowes to spawn programms hidden, waiting etc.
159 class CCommandd
: public CCommand
163 CCommandd( ByteString
&rString
, CommandBits nBits
);
164 CCommandd( const char *pChar
, CommandBits nBits
);