本文整理汇总了C++中ACE_Process_Options类的典型用法代码示例。如果您正苦于以下问题:C++ ACE_Process_Options类的具体用法?C++ ACE_Process_Options怎么用?C++ ACE_Process_Options使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ACE_Process_Options类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run_auto_test
/* \brief Just runs automatic tests
Function sends a number of datagrams, spawns child thread or process and
tries to receive at least one datagram.
\retval 0 datagram was received
\retval -1 datagram was not received
*/
int run_auto_test (const ACE_TCHAR *prog_name)
{
#if defined (ACE_HAS_PROCESS_SPAWN)
ACE_DEBUG ((LM_INFO, ACE_TEXT ("Running auto_tests in process mode\n")));
ACE_Process_Options opts;
pid_t child_pid;
opts.command_line (ACE_TEXT ("%s -p %d -t %d -a -r"),
prog_name, dgram_port, dgram_recv_timeout.msec ());
if ((child_pid = ACE_Process_Manager::instance ()->spawn (opts)) == -1)
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("spawn_n()")), -1);
#elif defined (ACE_HAS_THREADS)
ACE_UNUSED_ARG (prog_name);
ACE_DEBUG ((LM_INFO, ACE_TEXT ("Running auto_tests in thread mode\n")));
if (ACE_Thread_Manager::instance ()->spawn (run_thread_receiver) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("spawn_n ()")), -1);
#else
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("Cannot run in auto_test mode without fork or threads.\n")),
-1);
#endif /* defined (ACE_HAS_PROCESS_SPAWN) */
ACE_DEBUG ((LM_INFO,
ACE_TEXT ("Sending datagrams on port %d in auto_test mode\n"),
dgram_port));
ACE_SOCK_Dgram_Bcast socket;
if (socket.open (ACE_Addr::sap_any) != -1)
{
// send datagrams until child finishes
while (1)
{
send_datagram (socket, dgrams_no--);
ACE_Time_Value child_timeout (1);
#if defined (ACE_HAS_PROCESS_SPAWN)
if (ACE_Process_Manager::instance ()->wait (child_pid,
child_timeout,
&receiver_exit_code) == child_pid)
break;
#else /* ACE_HAS_THREADS */
// sleep 1 second or wait for child thread
child_timeout += ACE_OS::gettimeofday () ;
if (ACE_Thread_Manager::instance ()->wait (&child_timeout) == 0)
break;
#endif
}
socket.close ();
ACE_DEBUG ((LM_INFO, ACE_TEXT ("Child finished with %d exit code\n"),
receiver_exit_code));
}
else
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
ACE_TEXT ("Cannot open broadcast socket")), -1);
return (receiver_exit_code);
}
示例2: run_parent
void
run_parent (bool inherit_files)
{
ACE_TCHAR t[] = ACE_TEXT ("ace_testXXXXXX");
// Create tempfile. This will be tested for inheritance.
ACE_TCHAR tempfile[MAXPATHLEN + 1];
if (ACE::get_temp_dir (tempfile, MAXPATHLEN - sizeof (t)) == -1)
ACE_ERROR ((LM_ERROR, ACE_TEXT ("Could not get temp dir\n")));
ACE_OS::strcat (tempfile, t);
ACE_HANDLE file_handle = ACE_OS::mkstemp (tempfile);
if (file_handle == ACE_INVALID_HANDLE)
ACE_ERROR ((LM_ERROR, ACE_TEXT ("Could not get temp filename\n")));
// Build child options
ACE_TString exe_sub_dir;
const char *subdir_env = ACE_OS::getenv ("ACE_EXE_SUB_DIR");
if (subdir_env)
{
exe_sub_dir = ACE_TEXT_CHAR_TO_TCHAR (subdir_env);
exe_sub_dir += ACE_DIRECTORY_SEPARATOR_STR;
}
ACE_Process_Options options;
options.command_line (ACE_TEXT (".") ACE_DIRECTORY_SEPARATOR_STR
ACE_TEXT ("%sProcess_Test")
ACE_PLATFORM_EXE_SUFFIX
ACE_TEXT (" -c -h %d -f %s"),
exe_sub_dir.c_str(),
(int)inherit_files,
tempfile);
options.handle_inheritance (inherit_files); /* ! */
// Spawn child
ACE_Process child;
pid_t result = child.spawn (options);
if (result == -1)
ACE_ERROR ((LM_ERROR, ACE_TEXT ("Parent could NOT spawn child process\n")));
else
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Parent spawned child process with pid = %d.\n"),
child.getpid ()));
ACE_exitcode child_status;
result = child.wait (&child_status);
if (result == -1)
ACE_ERROR ((LM_ERROR, ACE_TEXT ("Could NOT wait on child process\n")));
else if (child_status == 0)
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Child %d finished ok\n"),
child.getpid ()));
else
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Child %d finished with status %d\n"),
child.getpid (), child_status));
}
示例3: test_date
static void
test_date (void)
{
ACE_Process_Options options;
options.command_line (DATE_PATH);
// Try to create a new process running date.
ACE_Process new_process;
if (new_process.spawn (options) == -1)
{
int const error_number = ACE_OS::last_error ();
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("%p errno = %d.\n"),
ACE_TEXT ("test_date"),
error_number));
return;
}
ACE_exitcode status;
new_process.wait (&status);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Process exit with status %d\n"),
status));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("date succeeded.\n")));
}
示例4: test_more
// This shows how to set handles.
static void
test_more (void)
{
ACE_HANDLE infile = ACE_OS::open (print_file, O_RDONLY);
if (infile == ACE_INVALID_HANDLE)
{
ACE_ERROR ((LM_DEBUG, ACE_TEXT ("%p\n"), print_file));
return;
}
ACE_Process new_process;
ACE_Process_Options options;
options.command_line (executable);
options.set_handles (infile);
if (new_process.spawn (options) == -1)
{
int const error_number = ACE_OS::last_error ();
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("%p errno = %d.\n"),
ACE_TEXT ("test_more"),
error_number));
}
ACE_exitcode status;
new_process.wait (&status);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Process exit with status %d\n"),
status));
ACE_OS::close (infile);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("More succeeded.\n")));
}
示例5: command_line_test
static int
command_line_test (void)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Testing for last character of command line\n")));
int result = 0;
const ACE_TCHAR *command = ACE_TEXT ("test Hello");
size_t command_len = ACE_OS::strlen (command);
ACE_Process_Options options (1, command_len + 1);
#ifndef ACE_LACKS_VA_FUNCTIONS
options.command_line (command);
#endif
ACE_TCHAR * const *procargv = options.command_line_argv ();
if (ACE_OS::strcmp (procargv [1], ACE_TEXT ("Hello")) != 0)
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("command_line_test failed: expected \"%s\"; got \"%s\"\n"),
ACE_TEXT ("Hello"),
procargv [1]));
result = 1;
}
return result;
}
示例6: test_setenv
int
test_setenv (void)
{
int status = 0;
ACE_Process_Options opts;
ACE_TCHAR bigval[5010] = ACE_TEXT ("");
for (int i = 0; i < 100; ++i)
ACE_OS::strcat (bigval,
ACE_TEXT ("01234567890123456789012345678901234567890123456789"));
#ifndef ACE_LACKS_VA_FUNCTIONS
# if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
const ACE_TCHAR *fmt = ACE_TEXT ("%ls");
# else
const ACE_TCHAR *fmt = ACE_TEXT ("%s");
# endif
if (0 != opts.setenv (ACE_TEXT ("A"), fmt, bigval))
{
status = errno;
ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("setenv")));
}
else
{
size_t env_len = ACE_OS::strlen (opts.env_buf ());
if (env_len != 5002)
{
status = 1;
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("setenv result should be 5002 chars, not %B\n"),
env_len));
}
}
#endif
return status;
}
示例7: test_setenv
static void
test_setenv (const ACE_TCHAR *argv0)
{
ACE_Process_Options options;
// options.setenv ("ACE_PROCESS_TEST", "here's a really large number: %u", 0 - 1);
options.setenv (ACE_TEXT ("ACE_PROCESS_TEST= here's a large number %u"),
0 - 1);
options.setenv (ACE_TEXT ("ACE_PROCESS_TEST2"), ACE_TEXT ("ophilli"));
#if defined (ACE_WIN32) || !defined (ACE_USES_WCHAR)
options.command_line ("%s -g", argv0);
#else
options.command_line ("%ls -g", argv0);
#endif
ACE_Process process;
if (process.spawn (options) == -1)
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("%p.\n"),
ACE_TEXT ("test_setenv")));
return;
}
ACE_exitcode status;
process.wait (&status);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Process exit with status %d\n"),
status));
}
示例8: test_ls
static void
test_ls (void)
{
ACE_Process_Options options;
#if defined (ACE_WIN32) || !defined (ACE_USES_WCHAR)
options.command_line (ACE_TEXT ("%s -al"), LS_PATH);
#else
options.command_line (ACE_TEXT ("%ls -al"), LS_PATH);
#endif
ACE_Process new_process;
if (new_process.spawn (options) == -1)
{
int error_number = ACE_OS::last_error ();
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("%p errno = %d.\n"),
ACE_TEXT ("test_ls"),
error_number));
}
ACE_exitcode status;
new_process.wait (&status);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Process exit with status %d\n"),
status));
}
示例9: command
int CC_Start_Cmd::execute(void)
{
if (excep_)
{
ACE_OS::printf ("Exception: %s\n", excep_->_rep_id ());
delete excep_;
excep_ = 0;
return 0; // CC_FAIL
}
ACE_OS::printf ("Executing start command (script file: %s)\n", cfg_name_);
char cmd_line[1024];
int success = ACE_OS::sprintf(&cmd_line[0], "%s -c %s",
"./CC_client", cfg_name_);
if(success>=1024 || success==-1)
ACE_ERROR_RETURN((LM_ERROR, "Creation of process failed: %s\n",
cmd_line), 0);
ACE_Process new_process;
ACE_Process_Options options;
options.command_line(ACE_TEXT_CHAR_TO_TCHAR(cmd_line));
if(new_process.spawn(options) == -1)
{
ACE_ERROR_RETURN((LM_ERROR, "Creation of process failed: %C\n",
cmd_line), 0);
}
return 1; // CC_SUCCESS
}
示例10: ACE_TMAIN
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
// Estabish call backs and socket names.
port1 = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_DEFAULT_SERVER_PORT;
const ACE_TCHAR *remotehost = argc > 2 ? argv[2] : ACE_DEFAULT_SERVER_HOST;
const u_short port2 = argc > 3 ? ACE_OS::atoi (argv[3]) : port1 + 1;
// Providing the fourth command line argument indicate we don't want
// to spawn a new process. On Win32, we use this to exec the new
// program.
if (argc > 4)
run_test (port1, remotehost, port2, argv[4]);
else
{
ACE_DEBUG ((LM_DEBUG,
"(%P|%t) local port = %d, remote host = %s, remote port = %d\n",
port1,
remotehost,
port2));
ACE_Process_Options options;
options.command_line (ACE_TEXT ("%s %d %s %d %c"),
argv[0],
port1,
remotehost,
port2,
'c');
// This has no effect on NT and will spawn a process that exec
// the above run_test function.
options.creation_flags (ACE_Process_Options::NO_EXEC);
ACE_Process new_process;
switch (new_process.spawn (options))
{
case -1:
return -1;
case 0:
run_test (port1,
remotehost,
port2,
ACE_TEXT("peer1"));
break;
default:
run_test (port2,
remotehost,
port1,
ACE_TEXT("peer2"));
new_process.wait ();
break;
}
}
return 0;
}
示例11: respawn_self
static pid_t
respawn_self (const ACE_TCHAR *myname,
int iter,
int exit_code)
{
ACE_Process_Options options;
options.command_line ("%s -c -i %d -e %d",
myname,
iter,
exit_code);
return ACE_Process_Manager::instance ()->spawn (options);
}
示例12: ACE_TMAIN
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
if (argc > 1) // Running as a child.
{
ACE_OS::sleep (10);
}
else // Running as a parent.
{
// Get the processwide process manager.
ACE_Process_Manager* pm = ACE_Process_Manager::instance ();
// Specify the options for the new processes
// to be spawned.
ACE_Process_Options options;
options.command_line (ACE_TEXT ("%s a"), argv[0]);
// Spawn two child processes.
pid_t pids[NCHILDREN];
pm->spawn_n (NCHILDREN, options, pids);
// Destroy the first child.
pm->terminate (pids[0]);
// Wait for the child we just terminated.
ACE_exitcode status;
pm->wait (pids[0], &status);
// Get the results of the termination.
#if !defined(ACE_WIN32)
if (WIFSIGNALED (status) != 0)
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("%d died because of a signal ")
ACE_TEXT ("of type %d\n"),
pids[0], WTERMSIG (status)));
#else
ACE_DEBUG
((LM_DEBUG,
ACE_TEXT ("The process terminated with exit code %d\n"),
status));
#endif /*ACE_WIN32*/
// Wait for all (only one left) of the
// children to exit.
pm->wait (0);
}
return 0;
}
示例13: setup_unnamed_pipe
static int
setup_unnamed_pipe (ACE_Process_Options &opt)
{
// Create an unnamed pipe instance.
ACE_Pipe pipe;
// Check if the pipe is created successfully.
if (pipe.open () == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "pipe.open"), -1);
// Setting up pipe between parent and child process. Use the pipe
// as child process'es ACE_STDIN. ACE_Process_Options will keep
// copies (by dup) of fd's that we pass in. Notice that we have to
// specify child process to use ACE_STDOUT for output explicitly
// because we'll close it down in the line after. Child process
// will use whatever we use to dup2 ACE_STDOUT as its stdout.
opt.set_handles (pipe.read_handle (), ACE_STDOUT);
// The previous keep a copy of original ACE_STDOUT fd, now we
// can replace ACE_STDOUT of parent process to the pipe.
ACE_OS::dup2 (pipe.write_handle (), ACE_STDOUT);
// Don't forget to close the unused fd.
pipe.close ();
return 0;
}
示例14: pref
int
launcher_rvgl::_launch(const std::string &host_id) {
if (_running) return err_already_running;
std::string dir = pref()->get<std::string>("advanced/rvgl_path", "");
std::string params = pref()->get<std::string>("advanced/rvgl_cmdline", "");
if (dir.empty()) {
win_registry r(win_registry::id_dplay, "", "Re-Volt");
dir = r.get<std::string>("Path", "");
pref()->set("advanced/rvgl_path", dir.c_str());
}
std::string cmd(dir);
#ifdef WIN32
cmd += "/rvgl.exe";
#else
cmd += "/rvgl";
#endif
cmd = "\"" + cmd + "\"";
if (!params.empty()) cmd += " " + params;
cmd += (host_id.empty() ? " -lobby" : " -lobby " + host_id);
//printf("%s\n", cmd.c_str());
ACE_DEBUG((LM_DEBUG, "launcher_rvgl: command line: %s\n",
cmd.c_str()));
// Launch options
ACE_Process_Manager *pm = ACE_Process_Manager::instance();
ACE_Process_Options opts;
opts.working_directory(dir.c_str());
opts.command_line(cmd.c_str());
_rvgl_pid = pm->spawn(opts, this);
ACE_DEBUG((LM_INFO, "launcher_rvgl: pid %d from thread %t, cmd: %s\n",
_rvgl_pid, cmd.c_str()));
if (_rvgl_pid == ACE_INVALID_PID) {
ACE_ERROR((LM_ERROR, "launcher_rvgl: failed to launch: %s\n",
cmd.c_str()));
return err_could_not_launch;
}
_running = true;
return 0;
}
示例15: run_realmd
bool Service_Manager::run_realmd()
{
ACE_ARGV realmd_args;
realmd_args.add(this->args.argv()[0]);
realmd_args.add("runrealmd");
ACE_Process_Manager* pmgr = ACE_Process_Manager::instance();
ACE_Process_Options pop;
pop.command_line(realmd_args.argv());
pid_t realmpid = pmgr->spawn(pop);
if (realmpid == ACE_INVALID_PID)
return false;
ServiceInfo *si = new ServiceInfo(realmpid);
this->svcs.insert(std::pair<MorpheusServices, ServiceInfo*>(LOGINSERVER, si));
ACE_DEBUG((LM_DEBUG,"Realmd runs at pid %u\n", realmpid));
return true;
}