Back to index

nordugrid-arc-nox  1.1.0~rc6
test_run.cpp
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
00002 
00003 #ifdef HAVE_CONFIG_H
00004 #include <config.h>
00005 #endif
00006 
00007 #include "Logger.h"
00008 #include "Run.h"
00009 #include "Thread.h"
00010 #include <string>
00011 #include <iostream>
00012 #ifdef WIN32
00013 #include "win32.h"
00014 #endif
00015 
00016 #include <glibmm.h>
00017 #include <unistd.h>
00018 #include <signal.h>
00019 
00020 /*
00021    Arc::Run *executer = NULL;
00022 
00023    void start_thread(void *)
00024    {
00025  #if 0
00026    std::cout << "Start" << std::endl;
00027       std::string cmdline = "test2";
00028       std::string working_directory = ".";
00029       Glib::Pid pid_;
00030       Glib::ArrayHandle<std::string> argv_(Glib::shell_parse_argv(cmdline));
00031       Glib::spawn_async_with_pipes(working_directory,
00032                                    argv_,
00033                                    Glib::SpawnFlags(0),
00034                                    sigc::slot<void>(),
00035                                                    &pid_,
00036                                    NULL,
00037                                    NULL,
00038                                    NULL);
00039    std::cout << "End" << std::endl;
00040  #endif
00041     std::cout << "Start" << std::endl;
00042     try {
00043         std::string std_in;
00044         std::string std_out;
00045         std::string std_err;
00046 
00047         executer = new Arc::Run("/bin/sleep 60");
00048         // executer = new Arc::Run("C:/msys/bin/sleep.exe 60");
00049         // executer = new Arc::Run("/c/msys/bin/sleep.exe 60");
00050         // executer = new Arc::Run("C:/ARC/arc1-new/src/hed/libs/common/PCP.exe c:/ARC/arc1-new/src/hed/libs/common/input.txt");
00051         // executer = new Arc::Run("C:/ARC/arc1-new/src/hed/libs/common/test2.exe");
00052 
00053         executer->AssignStdin(std_in);
00054         executer->AssignStdout(std_out);
00055         executer->AssignStderr(std_err);
00056 
00057         if (!executer->Start()) {
00058             std::cout << "Failed to start" << std::endl;
00059             return;
00060         };
00061    std::cout << "Wait" << std::endl;
00062         if (executer->Wait()) {
00063             std::cout << "End of run" << std::endl;
00064             std::cout << std_out << std::endl;
00065         } else {
00066             std::cout << "Timeout" << std::endl;
00067         }
00068     } catch (std::exception &e) {
00069         std::cout << e.what() << std::endl;
00070     } catch (Glib::SpawnError &e) {
00071         std::cout << e.what() << std::endl;
00072     }
00073     std::cout << "end of start_thread" << std::endl;
00074    }
00075 
00076    void stop_thread(void *)
00077    {
00078  #if 0
00079     sleep(10);
00080    std::cout << "Kill" << std::endl;
00081     executer->Kill(1);
00082    std::cout << "Killed" << std::endl;
00083  #endif
00084    }
00085 
00086    int main(void)
00087    {
00088    std::cout << "main start" << std::endl;
00089     Arc::CreateThreadFunction(&start_thread, NULL);
00091     for (int i = 0; i < 100; i++) {
00092    std::cout << "Main: " << i << std::endl;
00093     sleep(1);
00094    }
00095    std::cout << "main end" << std::endl;
00096     return 0;
00097    }
00098  */
00099 
00100 int main(void) {
00101   signal(SIGTTOU, SIG_IGN);
00102   std::string out;
00103   Arc::Run run("/bin/cat /tmp/*");
00104   run.AssignStdout(out);
00105   run.KeepStderr(true);
00106   run.KeepStdin(true);
00107   sleep(10);
00108   run.Start();
00109   if (run.Wait()) {
00110     std::cerr << "Success" << std::endl;
00111     std::cout << out << std::endl;
00112   }
00113   else
00114     std::cerr << "Timeout" << std::endl;
00115   sleep(600);
00116   return 0;
00117 }