2 * Copyright 2007 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Ramshankar, v.ramshankar@gmail.com
8 #ifndef _COMMAND_PIPE_H
9 #define _COMMAND_PIPE_H
27 virtual ~BCommandPipe();
29 status_t
AddArg(const char* argv
);
30 void PrintToStream() const;
32 // FlushArgs() deletes the commands while Close() explicity closes all
34 // Note: Internally FlushArgs() calls Close()
38 // You MUST NOT free/delete the strings in the array, but you MUST free
39 // just the array itself.
40 const char** Argv(int32
& _argc
) const;
42 // If you use these, you must explicitly call "close" for the parameters
43 // (stdOut/stdErr) when you are done with them!
44 thread_id
Pipe(int* stdOut
, int* stdErr
) const;
45 thread_id
Pipe(int* stdOut
) const;
46 thread_id
PipeAll(int* stdOutAndErr
) const;
48 // If you use these, you need NOT call "fclose" for the parameters
49 // (out/err) when you are done with them, also you need not do any
50 // allocation for these FILE* pointers, just use FILE* out = NULL
51 // and pass &out and so on...
52 thread_id
PipeInto(FILE** _out
, FILE** _err
);
53 thread_id
PipeInto(FILE** _outAndErr
);
55 // Run() is a synchronous call, and waits till the command has finished
56 // executing RunAsync() is an asynchronous call that returns immediately
57 // after launching the command Neither of these bother about redirecting
58 // pipes for you to use
62 // Reading the Pipe output
66 virtual ~LineReader() {}
67 virtual bool IsCanceled() = 0;
68 virtual status_t
ReadLine(const BString
& line
) = 0;
69 // TODO: Add a Timeout() method.
72 // This function reads line-by-line from "file". It calls IsCanceled()
73 // on the passed LineReader instance for each byte read from file
74 // (currently). And it calls ReadLine() for each complete line.
75 status_t
ReadLines(FILE* file
, LineReader
* lineReader
);
76 // This method can be used to read the entire file into a BString.
77 BString
ReadLines(FILE* file
);
79 // Stardard append operators, if you use pointers to a BCommandPipe,
80 // you must use *pipe << "command"; and not pipe << "command" (as it
81 // will not compile that way)
82 BCommandPipe
& operator<<(const char* arg
);
83 BCommandPipe
& operator<<(const BString
& arg
);
84 BCommandPipe
& operator<<(const BCommandPipe
& arg
);
94 } // namespace BPrivate
96 using BPrivate::BCommandPipe
;
98 #endif // _COMMAND_PIPE_H