execute an external EXE file using execl()


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:



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

Thank you in advance
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I take it that the form of the string passed to system() is to be

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

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...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
david_2005Author Commented:
I think I have to use execl() to execute an external EXE file ('nutsh'). Do you have any idea how to do that.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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
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?
david_2005Author Commented:
Thank you for your help.
I got this problem solve by myself already.
Well, you should give points anyway since we answered your question and told you where the problem with your code was.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.