Execute Command from C fcn in DLL

This is a discussion on Execute Command from C fcn in DLL within the Windows Programming forums, part of the Platform Specific Boards category; Execute a Dos Shell command from a C function in a DLL??? i.e. I have a program that I can ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    5

    Execute Command from C fcn in DLL

    Execute a Dos Shell command from a C function in a DLL???

    i.e. I have a program that I can execute from a Dos Prompt with parameters and this program will send an email.

    I want to execute this program with the parameters and have it send an email and then return control back to the function that it was called from. Or better yet I want the function to be able to execute this program and not wait for it to finish.

    anyone, pls, how can I do this??

    I have tried using system("...") but this freezes.
    I have tried execl - it compiles but does weird ........ when it runs.(is this meant for windows? - as far as i know only stuff meant for win should even compile, right?)
    When I try to #include <windows.h> then i get a linking error.

    can anyone pls help?

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You can look into the _spawnl function. Alternatively, the RunCommand function should do what you want.

    >> I have tried execl - it compiles but does weird ........ when it runs.(is this meant for windows? - as far as i know only stuff meant for win should even compile, right?) <<

    The idea with the exec functions is that they replace the current process with the new process. This means that an exec function will not return. Typically, on Windows, the exec function implementation will call exit(0) after starting the new process.

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    5
    These commands do nothing when I use them... im trying to execute a program with parameters that should send me an email when it works. i can execute the program from dos prompt and it works!!! but when i try to execute it using _spawnl it does nothing....

    The function is in a DLL that is linked with DB2 stuff and i execute it by calling it from DB2 SQL - and when i don't try and execute another process in it it returns the product of 2 numbers that I see output in SQL command prompt... but when i try to execute a process in it then it returns 1 ... perhaps being returned by the _spawnl call.

    I've been trying everything i find and nothing works. My last thought was that the environment was wrong (being linked with db2 stuff and all) so i wanted to use _spawnle but I can't find any documentation anywhere that says what environment variables to set to what in order to run the new process in a standard dos prompt way.

    can anyone please help?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. non-MFC DLL with MFC app question.
    By Kempelen in forum Windows Programming
    Replies: 10
    Last Post: 08-20-2008, 08:11 AM
  2. dll communicating between each other
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 06-17-2005, 03:20 AM
  3. DLL compiling question
    By Noose in forum Windows Programming
    Replies: 2
    Last Post: 12-16-2004, 07:16 AM
  4. DLL and std::string woes!
    By Magos in forum C++ Programming
    Replies: 7
    Last Post: 09-08-2004, 01:34 PM
  5. .lib vs .h vs .dll
    By Shadow12345 in forum C++ Programming
    Replies: 13
    Last Post: 01-01-2003, 05:29 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21