?
Solved

Call expect script from C Program

Posted on 2003-02-24
3
Medium Priority
?
706 Views
Last Modified: 2012-06-21
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.
-----------------------------------------
#!/bin/bash
smbclient \\\\Alpha\\Vax\ Data -U Administrator%block57 << EOC
put tables.txt
exit
EOC
--------------------------------------------------
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
John
0
Comment
Question by:jtrapat1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Accepted Solution

by:
honey_hamster earned 400 total points
ID: 8011865
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
script.

0
 
LVL 4

Expert Comment

by:pankajtiwary
ID: 8014222
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().
0
 
LVL 11

Expert Comment

by:cup
ID: 8019107
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?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses

777 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