2c.wxWidgets – Process Control

OVERVIEW

wxWidgets provides various functions to interact with the OS and call other applications.

wxShell() is used to run OS level commands. wxExecute() can also do the same thing, but it has the capability of running asynchronously and also capture the application output. wsExit() terminates the current program.

SAMPLE CODE

pcontrol.cpp
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
	#include <wx/wx.h>
#endif
#include <wx/app.h>

int main(int argc, char **argv) {
	wxInitialize();
	wxExecute(wxT("cal 2022"), wxEXEC_ASYNC);
	wxExecute(wxT("ls -l"));
	wxShell(wxT("cal"));
	unsigned long pid = wxGetProcessId();
	wxString strPid = wxString::Format(wxT("Process id=%zu"), pid);
	wxPuts(strPid);

	wxUninitialize();
	wxExit();
	

}

The output is given below:

                        2022   January               February               March          
 Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  
                    1         1  2  3  4  5         1  2  3  4  5  
  2  3  4  5  6  7  8   6  7  8  9 10 11 12   6  7  8  9 10 11 12  
  9 10 11 12 13 14 15  13 14 15 16 17 18 19  13 14 15 16 17 18 19  
 16 17 18 19 20 21 22  20 21 22 23 24 25 26  20 21 22 23 24 25 26  
 23 24 25 26 27 28 29  27 28                 27 28 29 30 31        
 30 31                                                             
    April                  May                   June          
 Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  
                 1  2   1  2  3  4  5  6  7            1  2  3  4  
  3  4  5  6  7  8  9   8  9 10 11 12 13 14   5  6  7  8  9 10 11  
 10 11 12 13 14 15 16  15 16 17 18 19 20 21  12 13 14 15 16 17 18  
 17 18 19 20 21 22 23  22 23 24 25 26 27 28  19 20 21 22 23 24 25  
 24 25 26 27 28 29 30  29 30 31              26 27 28 29 30        
     July                 August              September        
 Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  
                 1  2      1  2  3  4  5  6               1  2  3  
  3  4  5  6  7  8  9   7  8  9 10 11 12 13   4  5  6  7  8  9 10  
 10 11 12 13 14 15 16  14 15 16 17 18 19 20  11 12 13 14 15 16 17  
 17 18 19 20 21 22 23  21 22 23 24 25 26 27  18 19 20 21 22 23 24  
 24 25 26 27 28 29 30  28 29 30 31           25 26 27 28 29 30     
 31                                                                
   October               November              December        
 Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  
                    1         1  2  3  4  5               1  2  3  
  2  3  4  5  6  7  8   6  7  8  9 10 11 12   4  5  6  7  8  9 10  
  9 10 11 12 13 14 15  13 14 15 16 17 18 19  11 12 13 14 15 16 17  
 16 17 18 19 20 21 22  20 21 22 23 24 25 26  18 19 20 21 22 23 24  
 23 24 25 26 27 28 29  27 28 29 30           25 26 27 28 29 30 31  
 30 31                                                             
 total 48024
 -rwxrwxr-x 1 amit amit 7016344 Dec 11 10:55 console
 -rw-rw-r-- 1 amit amit     392 Dec 11 10:55 console.cpp
 -rwxrwxr-x 1 amit amit 7022224 Dec 11 10:42 datetime
 -rw-rw-r-- 1 amit amit    1023 Dec 11 10:41 datetime.cpp
 -rwxrwxr-x 1 amit amit 7016456 Dec 11 10:43 directory
 -rw-rw-r-- 1 amit amit     805 Dec 11 10:42 directory.cpp
 -rw-rw-r-- 1 amit amit      63 Dec 11 10:43 file.dat
 -rwxrwxr-x 1 amit amit 7024624 Dec 11 10:43 filereadwrite
 -rw-rw-r-- 1 amit amit     811 Dec 11 10:42 filereadwrite.cpp
 -rwxrwxr-x 1 amit amit 7017216 Dec 11 10:44 pcontrol
 -rw-rw-r-- 1 amit amit     389 Dec 11 10:42 pcontrol.cpp
 -rwxrwxr-x 1 amit amit 7010784 Dec 11 10:44 platform
 -rw-rw-r-- 1 amit amit     275 Dec 11 10:42 platform.cpp
 -rwxrwxr-x 1 amit amit 7023184 Dec 11 10:58 strings
 -rw-rw-r-- 1 amit amit     920 Dec 11 10:58 strings.cpp
    December 2021      
 Su Mo Tu We Th Fr Sa  
           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     
 Process id=16216

1 Trackback / Pingback

  1. 1.wxWidgets – Introduction – Truelogic Blog

Leave a Reply

Your email address will not be published.


*