i have two programs..
say 1) intermediate.c ( which creates and intermediate file )
2) result.c ( which creates final csv file)..

is it possible when i execute second program, first automatically generate the intermediate file which is being used in second program?

Dani AI

Generated

Short answer: yes. There are three practical approaches depending on whether you want two separate programs or a single coordinated workflow.

As suggested, merging the two steps into one program (so the intermediate generation and final CSV creation run under the same process) avoids most synchronization headaches. If you must keep separate executables, the simplest and most robust solution is an orchestrator: a small wrapper (shell/batch script, Makefile rule, or a tiny C launcher) that runs the first program, checks its exit code, then runs the second. See the GNU Make manual for dependency-driven builds: GNU Make manual.

If the second program should start as soon as the intermediate file appears (or stream data), use one of these IPC/coordination patterns instead of polling:

  • Pipe or popen-style streaming when program1 can write to stdout and program2 reads stdin: popen(3).
  • Named pipes/sockets for a producer/consumer stream.
  • File-watching APIs to react to file creation: use inotify on Linux (inotify(7)) or ReadDirectoryChangesW on Windows (ReadDirectoryChangesW).

For spawning processes from C, use the platform APIs rather than ad-hoc timing: POSIX offers fork/exec or posix_spawn (fork(2), posix_spawn); Windows uses CreateProcess and wait functions (CreateProcess, WaitForSingleObject).

Important cautions: avoid race conditions and partial reads by writing to a temporary file and atomically renaming it (rename(2)), use file locks if needed (flock(2)), and call fsync before signaling readiness (fsync(2)). Also use absolute paths, check return codes, and log failures when troubleshooting.

Recommended Answers

All 4 Replies

Yes, if you have a multi-core processor then its possible to run both programs at the same time but I'm uncertain of how you would get the operating system to coordinate or make sure that when one is running then run the other...A better solution would be one program that has two threads.

Depending on your O/S, look up the system's Execute functions. There should be one that allows you to execute Program 1 and wait until it exits.

Other option is to run Program 1 and just before it exits, start program 2 with system()

okay thank you..
can i find any documents regarding this problem?

Probably. GOOGLE finds a lot of stuff for me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.