Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 711
  • Last Modified:

Call expect script from C Program

Can anyone help?
I am trying to call an expect script from inside a C Program and I don't know how.
My expect script simply locates a remote server and writes a file to a directory on that server.
Here's my script:
I have the filename hard-coded for now but later I will have to pass the file name as a parameter.
smbclient \\\\Alpha\\Vax\ Data -U Administrator%block57 << EOC
put tables.txt
I can't find the best method of calling this script.
A systems person told me to use popen but I also found spawn, spawnl, and exec.
Can anyone tell me the best method to use for my case?

Thanks in Advance
1 Solution
Have you looked into system()?

In your 'C' code you would have:

  system( "script_name parm" );

Where script_name is the name of your script,
and parm is a parameter value. In other words, the
string parameter you pass to system() is the same as
what you'd type at the command line to invoke your

Well, You can use exec() family of system calls. There are a total of 6 members in this family. You can use depending on your requirement. This is also another way of creating a process. But the only difference in fork() and exec() is that fork() runs the new process along with the original process i.e. The two processes are different. Their process IDs will be different while exec() creates the new process on top of the original process. So, for some amount of time, the process ID of the original process is assigned to the new process and when exec() returns, the original process resumes. You can see the documentation of exec().
I don't think it is a good idea to call expect from a C program or from any program.  expect pretends to be the keyboard and does strange things with pipes etc.  If you're running a C program, there is no keyboard.

Isn't there another way of solving your problem other than calling expect through a C program?

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now