blob: 5e4ddf1a0d3720c4b6adde5878768d3097cb118a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
#ifndef SHELL_EXECUTE_H_23482134578134134
#define SHELL_EXECUTE_H_23482134578134134
#include "file_error.h"
#include "thread.h"
#include <stdlib.h> //::system()
namespace zen
{
//launch commandline and report errors via popup dialog
//windows: COM needs to be initialized before calling this function!
enum ExecutionType
{
EXEC_TYPE_SYNC,
EXEC_TYPE_ASYNC
};
namespace
{
void shellExecute(const Zstring& command, ExecutionType type) //throw FileError
{
/*
we cannot use wxExecute due to various issues:
- screws up encoding on OS X for non-ASCII characters
- does not provide any reasonable error information
- uses a zero-sized dummy window as a hack to keep focus which leaves a useless empty icon in ALT-TAB list in Windows
*/
if (type == EXEC_TYPE_SYNC)
{
//Posix::system - execute a shell command
int rv = ::system(command.c_str()); //do NOT use std::system as its documentation says nothing about "WEXITSTATUS(rv)", ect...
if (rv == -1 || WEXITSTATUS(rv) == 127) //http://linux.die.net/man/3/system "In case /bin/sh could not be executed, the exit status will be that of a command that does exit(127)"
throw FileError(_("Incorrect command line:") + L"\n" + utfTo<std::wstring>(command));
}
else
runAsync([=] { int rv = ::system(command.c_str()); (void)rv; });
}
}
}
#endif //SHELL_EXECUTE_H_23482134578134134
|