* @brief Execute command in shell and provide its results * @attention Not thread-safe */
| 350 | * @attention Not thread-safe |
| 351 | */ |
| 352 | class TShellCommand: public TMoveOnly { |
| 353 | private: |
| 354 | TShellCommand(); |
| 355 | |
| 356 | public: |
| 357 | enum ECommandStatus { |
| 358 | SHELL_NONE, |
| 359 | SHELL_RUNNING, |
| 360 | SHELL_FINISHED, |
| 361 | SHELL_INTERNAL_ERROR, |
| 362 | SHELL_ERROR |
| 363 | }; |
| 364 | |
| 365 | public: |
| 366 | /** |
| 367 | * @brief create the command with initial arguments list |
| 368 | * |
| 369 | * @param cmd binary name |
| 370 | * @param args arguments list |
| 371 | * @param options execution options |
| 372 | * @todo store entire options structure |
| 373 | */ |
| 374 | TShellCommand(const TStringBuf cmd, const TList<TString>& args, const TShellCommandOptions& options = TShellCommandOptions(), |
| 375 | const TString& workdir = TString()); |
| 376 | TShellCommand(const TStringBuf cmd, const TShellCommandOptions& options = TShellCommandOptions(), const TString& workdir = TString()); |
| 377 | ~TShellCommand(); |
| 378 | |
| 379 | public: |
| 380 | /** |
| 381 | * @brief append argument to the args list |
| 382 | * |
| 383 | * @param argument string argument |
| 384 | * |
| 385 | * @return self |
| 386 | */ |
| 387 | TShellCommand& operator<<(const TStringBuf argument); |
| 388 | |
| 389 | /** |
| 390 | * @brief return the collected output from the command. |
| 391 | * If the output stream is set, empty string will be returned |
| 392 | * |
| 393 | * @return collected output |
| 394 | */ |
| 395 | const TString& GetOutput() const; |
| 396 | |
| 397 | /** |
| 398 | * @brief return the collected error output from the command. |
| 399 | * If the error stream is set, empty string will be returned |
| 400 | * |
| 401 | * @return collected error output |
| 402 | */ |
| 403 | const TString& GetError() const; |
| 404 | |
| 405 | /** |
| 406 | * @brief return the internal error occured while watching |
| 407 | * the command execution. Should be called if execution |
| 408 | * status is SHELL_INTERNAL_ERROR |
| 409 | * |
no test coverage detected