Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass Arguments to a C Program

Status
Not open for further replies.

jamez05

Programmer
Jul 29, 2005
130
US
I have a windows program that I need to pass a
string to via ColdFusion and have it return a value
back to Coldfusion. I understand the ColdFusion part,
but I am very new to C programming.

I'm assuming all you have to do is add an argument to the
main function, is this correct?

main(char externalstring[50]) {

}

Additionally, the program has 9 objects. I'm assuming you
place the nine objects in the folder ColdFusion accesses (map the path etc..) and just call the main object from ColdFusion. Does this sound correct? I compiled it as as WIn32 Console application. Can I just grab the object files or should I be creating a different type of program?

Any help is greatly appreciated.

James
 
main gets it's command line parameters as follows
Code:
#include <stdio.h>

int main ( int argc, char *argv[] ) {
  int i;
  for ( i = 0 ; i < argc ; i++ ) {
    printf( "Argument %d is %s\n", i, argv[i] );
  }
  return 0;
}

Example
[tt]> gcc hello.c
> ./a.out hello world
Argument 0 is ./a.out
Argument 1 is hello
Argument 2 is world
[/tt]

> and have it return a value back to Coldfusion.
What do you mean - a value?
An integer or a string?


--
 
Thanks for replying.

The program has to pass back some strings. If there are no errors, it passes back a chemical string. If there are errors, it needs to pass back the error messages. Its basically a function that is too complex to re-write in ColdFusion.
 
You could write the strings to one or more files and then read the files into your Coldfusion ap.

You would test the return value from the C program to detect an error state.

The return value of a C program is normally 0 (zero) if the program is happy, and any other (integer) value if it isn't happy.

 
You want to write a Custom Tag for Cold Fusion using vc++ and that tag would call your C code. A method other than main can return arrays and structures.

The Cold Fusion CDs have an installation option that adds the CF Tag wizard to uyour VC++ environment,

Check in the Cold Fusion section. I would assume they have one here...

Jeb Beasley
 
As an alternate or workaround you could write a cgi program in C or any language. It will take all input as string data, and return all output as a string. CF can read a URL into a variable and you can parse it as you wish.

See the cfhttp tag for more info

There are some easy to use 'cgic' libraries out there to make things easier.

Jeb Beasley
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top