?
Solved

execute an external EXE file using execl()

Posted on 2004-11-06
7
Medium Priority
?
327 Views
Last Modified: 2010-04-17
hi,

I want to execute an external executable file (nutsh),

and now I am using  system() . I think this is completely wrong but I dont know how to fix it. Can I get some help!

here is links to my code and exec file:

http://www.cox-internet.com/nguyen/work.cpp

http://www.cox-internet.com/nguyen/nutsh

Please tell me what have I done wrong, and how can I fix it

Thank you in advance
0
Comment
Question by:david_2005
  • 3
  • 2
  • 2
7 Comments
 
LVL 19

Assisted Solution

by:mrwad99
mrwad99 earned 800 total points
ID: 12514321
I take it that the form of the string passed to system() is to be

echo ./tmp/nutsh | <parameter passed to redirectOutput()>

?
0
 
LVL 19

Accepted Solution

by:
mrwad99 earned 800 total points
ID: 12514335
If that is the case, this works fine

      char szCommandLine[1024];
      char szCopyCmd[512];

      // Copy the input parameter to temporary buffer szCopyCmd
      strcpy(szCopyCmd, cmd);
      
      // Copy the first part of the command to szCommandLine
      strcpy(szCommandLine,"echo ./tmp/nutsh | ");
      
      // Concatenate szCopyCmd to szCommandLine
      strcat(szCommandLine, szCopyCmd);

Obviously this would be more efficient using malloc, but I could not see where you were getting the size of the memory to allocate, and your code will not compile as I use Windows...
0
 

Author Comment

by:david_2005
ID: 12514429
I think I have to use execl() to execute an external EXE file ('nutsh'). Do you have any idea how to do that.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 19

Expert Comment

by:mrwad99
ID: 12514438
Yeah I use it in Windows; but it would not be beneficial for me to point you at MSDN since you are on UNIX or similar.  Read http://linux.about.com/library/cmd/blcmdl3_execl.htm
0
 
LVL 11

Assisted Solution

by:lbertacco
lbertacco earned 200 total points
ID: 12516174
If you want to use the pipe "|", it's easier to stick to "system" and not "execl"

What exactly do you want to execute? Is "./tmp/nutsh" a program? Is it writing something in output? Why are you redirecting the output?
0
 

Author Comment

by:david_2005
ID: 12516184
Thank you for your help.
I got this problem solve by myself already.
0
 
LVL 11

Expert Comment

by:lbertacco
ID: 12517353
Well, you should give points anyway since we answered your question and told you where the problem with your code was.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Progress

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question