How do you call one program from another?

What I’m wondering is how running programs communicate with each other, and if someone could post some sample code for how to do this, so I can try it out myself, just for educational purposes.

For example, I’ve worked with databases before, and in my code I always have to “establish a connection to the database.” The database service has to be running before I start my program, or else it will fail. What exactly is going on with that connection and how does it work?

Any sort of communication with the outside world is ultimately mediated by the operating system. There’s various mechanisms available for Inter-process communication, but pipes and network sockets are probably some of the most common. If you’ve ever piped the output of one program into another on a command line shell, those processes were communicating with a pipe. The connection to the database you mentioned is using a network socket, perhaps with a custom protocol. For communicating separate machines in a fairly universal way, you’d probably go with a web service, which generally means passing information through HTTP and possibly XML.

3

There high-level communication possibilities:

  1. Remote Procedure Calls (Web Services, CORBA etc. included)
  2. File Transfer
  3. Shared Database
  4. Messaging (AMQP, ZeroMQ etc.)

There are also low-level communication possibilities:

  1. Sockets
  2. Pipes
  3. Shared-memory
  4. Signal

This is not such an easy question to be answered because it envolves distinct types of work.

For the case of a database, for example, it’s usually a connection to a server through TCP/IP protocol, and the database needs to be running because the server needs to be connected so that it receives the request from your code (think that you can’t access an offline website).

However, for the case of other programs, it depends a lot. If it’s just a module written in the same language, you could just import. If it’s a Unix process, you could call system function passing the command. If you want something to be multi-platform, you could use a Restful or a SOAP web service (that’d require internet connection), and so on.

2

To ensure that the database service is running , You can either check whether the service is running, and start or stop it accordingly.

for Windows you should use Windows API to do that accordingly.

here is the example code

http://msdn.microsoft.com/en-us/library/windows/desktop/ms686315(v=vs.85).aspx

and also a different approach here

http://code.msdn.microsoft.com/windowsdesktop/CppWindowsService-cacf4948

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật