Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Executing one program from within another

Name: Anonymous 2006-12-06 17:27

I was just thinking about how someone could do this, based on statements about how in the pre-gui days there were a lot of programs designed to just run other programs in sequence for user convenience, and after checking Google, I found this brief description of how to execute another program from within a C program:

http://antionline.com/showthread.php?t=273880

And elsewhere, a brief description of unistd.h and the definitions it contains. I can see a few neat uses for it, although some of those uses would be better fulfilled by simply adding the abilities of the foreign program to your header file, or some fancy use of a makefile.

One good use I can think of is doing this to make programs in different languages cooperate. And I'm wondering now how many languages I could get to talk to each other. C and C++ invoking each other is obvious. In an online, CGI environment, I might be able to cheat with fopen(page.php) to get the results of a PHP script, or it's possible neither fopen or execv will work correctly, but I'm confident I could get PHP to run C with eval(cprog.cgi) or file(cprog.cgi). I could do the same with any other language that can be used in CGI. Between C and JavaScript, I can at least get JS to run C with the same kind of request used for AJAX, although I don't think it's possible to do it the other way unless C actually interprets the JS itself. JS running PHP is kind of obvious, as that's what most AJAX does. What about doing it between other programming languages, or scripting languages more capable than JS?

Name: Anonymous 2006-12-06 19:21

C + AJAX = WIN AMIRITE

Name: Anonymous 2006-12-06 21:01

Uh... To launch stuff from C, you do system("..."), which is simple and portable, unless you want to customize process creation (then have a look at the exec*, spawn*, CreateProcess, etc. functions, but they are less comfortable and hardly portable).

One good use I can think of is doing this to make programs in different languages cooperate.
To do that, you use libraries and extensions. They are much faster and more comfortable to use, besides being able to share input and output data easily with you. For example, you can write a C extension for PHP that will supply PHP scripts with functions you wrote in C. You need to know quite a bit to do that though.

You can run external processes from PHP with system() too, but you should rarely need to.

You can't launch C code from JavaScript in a browser. Your AJAX server can be written in C, but that'd be such a pain. Not recommended. You can use JavaScript within a C program with a JavaScript interpreter such as Mozilla's SpiderMonkey, the one Firefox and SeaMonkey use.

Name: Anonymous 2006-12-06 22:17

The primary mission of information technology is to improve business processes and increase profits. Companies are constantly rethinking and struggling with how to use IT to a competitive advantage, reduce IT operating and maintenance costs, and reduce the total cost of ownership... all while attempting to deliver increased value.

Name: Anonymous 2006-12-07 0:37

>>2
Step 1. C
Step 2. AJAX
Step 3. ????
Step 4. Profit

Name: Anonymous 2006-12-07 1:28

LOL, OP is a fucking noob.

In the C class at my local community college, they cover this in the fourth class session.  (I didn't take the class myself, but saw my brother's syllabus.)

In all 4 of my C/UNIX programming textbooks, this is covered in the first 6 chapters.

HAY HERES ANOTHER 1337 H4K: RUNNING A PROGRAM COMPILED ON YOUR WINDOWS MACHINE... ON SOMEONE ELSES WINDOWS MACHINE!!!

Name: Anonymous 2006-12-07 2:00

The thing missing in your intro post is the whole concept of file streams. You seem entirely focused on "language calling language" when it's really more like "program calling program." The fact is that programs don't really care is written in Language X, so long as the OS is able to run it.

JS is an embedded language: it has no I/O of its own. It relies on its host to do that, browser or otherwise (e.g. the Sphere RPG engine uses JS).

If you're really deadset on getting JS running, you could wrap the SpiderMonkey JS lib around stdin/stdout/stderr. Instant JS interpreter.

Name: Anonymous 2006-12-07 2:06

#include <stdio.h>
int main)( }
printf)"I win(;
return 0;
{ am i right? //

Name: Anonymous 2006-12-07 13:17 (sage)

Name: Anonymous 2009-01-14 13:54

IHBTE

Name: Anonymous 2010-12-22 0:17

Name: Sgt.Kabu撋橒kiman⡠踷 2012-05-28 21:19

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List