Hi All,
I am calling one exe from my c++ code exe, now i want some(two or three) values in my c++ code exe from that exe which i am calling,
Any idea how can it be done?
Plz help me out in this.
Hi All,
I am calling one exe from my c++ code exe, now i want some(two or three) values in my c++ code exe from that exe which i am calling,
Any idea how can it be done?
Plz help me out in this.
Quick, practical options and pitfalls for returning a few values from a child EXE (answers tied to the posts above by , , and ).
If both programs are under your control and can be refactored, the cleanest solution is to convert the called EXE into a library (DLL/.so) and call its function(s) directly. That gives direct return values, proper types, exceptions, and avoids IPC complexity — but requires rebuilding and a stable API.
If refactoring is not possible, pick a simple, robust exchange format and a single channel for data. Have the child produce a compact, machine-parseable payload (one-line JSON, CSV, or key=value lines). Use stdout only for the payload and stderr for logs. The parent spawns the child, reads until EOF, then parses and validates the payload. Requirements to make this reliable: always flush the child’s output before exit, choose an unambiguous delimiter or length-prefix for binary blobs, and have a clear error/status field in the payload. Do not rely on environment variables to communicate values — a child cannot change the parent’s environment.
For higher-throughput, persistent, or concurrent exchanges use OS IPC designed for that purpose (shared memory / memory-mapped files, local sockets, or platform RPC/COM) and pay attention to synchronization, cleanup, and permissions.
A few cautions: exit codes are suitable only for tiny status info (on POSIX the visible exit status is typically limited to 0..255). If you use temporary files, create them atomically and securely (avoid predictable names). Always validate and sanitize any data from the child, and ensure proper cleanup on error paths.
Recommendation: for two or three values and minimal work, emit a short structured payload from the child and have the parent capture and parse it. If you expect tighter coupling or richer data, move to a library or an OS-level IPC mechanism.
Jump to Post— Ancient Dragon 5,243program A calls program B. Program B writes some stuff to a file and program A reads it. Or you could use pipes (see man pages for popen() )
program A calls program B. Program B writes some stuff to a file and program A reads it. Or you could use pipes (see man pages for popen() )
...Or you could use pipes (see man pages for popen() )
Or even named pipes which can be accessed just like any file
Niek
i think this topic is called interprocess communication {i am just starting learning about it..}
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.