04-08-2008
Tk you but...
Yes you are right is not a straight telnet is more something about writing a c program that sends shell commands and retrive the answer.
It's really hard to sync the input and the output from shell...
I worked around with the code and I figurated out that my problem was with:
execl("/bin/sh", "sh", "-c", command, NULL);
now I'm able to execute execl without open a new shell.
This command works well:
execl("/usr/bin/telnet", command, ip_add, port, NULL);
where telnet it's just an alias on this solaris...
I still have problem on sync the write and reading part of the pipes...
Tks alot,
ff
10 More Discussions You Might Find Interesting
1. Programming
i made a lot of processes. here is the code:
main()
{
printf("\nEnter K="); scanf("%d",&k);
printf("Enter L="); scanf("%d",&l);
printf("\nFather id=%d\n",getpid());
x=0;
makechild();
sleep(2);
return 1;
}
int makechild()
{
for(q=1;q<=k;q++)
{
if(f=fork())
{
... (5 Replies)
Discussion started by: bb666
5 Replies
2. UNIX for Dummies Questions & Answers
Hi there,
I try to use:
> find * | ls
but it just gave me one level of ' ls '. and it said:
> find * | ls
dir1 dir2 f1 f2 f3
Broken Pipe
>
what is broken pipe?
how can i fix it?
thks
Gusla (3 Replies)
Discussion started by: gusla
3 Replies
3. Shell Programming and Scripting
Somewhat long story:
I have a simple Perl CGI script that uses Expect to Telnet to a device and grab some data, and then spits it back to Perl for display on the Webpage.
This works for many devices I've tried, but one device just fails, it keeps rejecting the password on this device, only... (1 Reply)
Discussion started by: jondo
1 Replies
4. Shell Programming and Scripting
Hi, guys:
I am working on my shell using c. How can I use pipe to implement the following?
ls -l 1>> | grep hellp 1<< 2>> | less 2<<
(the output of ls goes to grep, and the output of grep goes to less)
Thanks
Please use and tags when posting code, data or logs etc. to preserve... (1 Reply)
Discussion started by: tomlee
1 Replies
5. Shell Programming and Scripting
Hi All ,
Is there any way to replace the pipe ( | ) with the broken pipe (0xA6) in unix (1 Reply)
Discussion started by: saj
1 Replies
6. UNIX for Dummies Questions & Answers
Hi,
I was writing one script which includes to switch to the another telnet automatically from the present telnet server. I was using rlogin but firstly it takes the same user name of the present telnet and secondly it is prompting for the password.
But i want to switch to the another telnet... (2 Replies)
Discussion started by: Prateek
2 Replies
7. UNIX for Dummies Questions & Answers
I have been using unix on and off for a number of years. I am not a sys admin. I use what I need. I have googled this, but I really can't figure out what is the difference between using xarg and just using a regular pipe? Why do I need to include xarg sometimes and how do I know when I need it? (2 Replies)
Discussion started by: guessingo
2 Replies
8. UNIX for Dummies Questions & Answers
I can use pipe output to a file. For example
./somescript.sh > output.txt
But for example if the output from ./somescript.sh is slow. like if it prints one line every minute then output.txt is not updated every minute. Lines are written to output.txt in one go, hence have to wait for the whole... (2 Replies)
Discussion started by: kevincobain2000
2 Replies
9. UNIX for Dummies Questions & Answers
Hi,
I want to know the difference between these two services. Both are under xinetd. Both are used for enabling and disabling Telnet service. So, can somebody please explain me the difference between the two ?
Thanks in advance :) (0 Replies)
Discussion started by: kashifsd17
0 Replies
10. Shell Programming and Scripting
Hi guys,
I need to know how i can ignore Pipe '|' if Pipe is coming as a column in Pipe delimited file
for eg:
file 1:
xx|yy|"xyz|zzz"|zzz|12...
using below awk command
awk 'BEGIN {FS=OFS="|" } print $3
i would get xyz
But i want as :
xyz|zzz to consider as whole column... (13 Replies)
Discussion started by: rohit_shinez
13 Replies
EXEC(2) System Calls Manual EXEC(2)
NAME
exec, execl, _clock - execute a file
SYNOPSIS
#include <u.h>
#include <libc.h>
int exec(char *name, char* argv[])
int execl(char *name, ...)
long *_clock;
DESCRIPTION
Exec and execl overlay the calling process with the named file, then transfer to the entry point of the image of the file.
Name points to the name of the file to be executed; it must not be a directory, and the permissions must allow the current user to execute
it (see stat(2)). It should also be a valid binary image, as defined in the a.out(6) for the current machine architecture, or a shell
script (see rc(1)). The first line of a shell script must begin with followed by the name of the program to interpret the file and any
initial arguments to that program, for example
#!/bin/rc
ls | mc
When a C program is executed, it is called as follows:
void main(int argc, char *argv[])
Argv is a copy of the array of argument pointers passed to exec; that array must end in a null pointer, and argc is the number of elements
before the null pointer. By convention, the first argument should be the name of the program to be executed. Execl is like exec except
that argv will be an array of the parameters that follow name in the call. The last argument to execl must be a null pointer.
For a file beginning #!, the arguments passed to the program (/bin/rc in the example above) will be the name of the file being executed,
any arguments on the #! line, the name of the file again, and finally the second and subsequent arguments given to the original exec call.
The result honors the two conventions of a program accepting as argument a file to be interpreted and argv[0] naming the file being exe-
cuted.
Most attributes of the calling process are carried into the result; in particular, files remain open across exec (except those opened with
OCEXEC OR'd into the open mode; see open(2)); and the working directory and environment (see env(3)) remain the same. However, a newly
exec'ed process has no notification handler (see notify(2)).
When the new program begins, the global cell _clock is set to the address of a cell that keeps approximate time expended by the process at
user level. The time is measured in milliseconds but is updated at a system-dependent lower rate. This clock is typically used by the
profiler but is available to all programs.
The above conventions apply to C programs; the raw system interface to the new image is as follows: the word pointed to by the stack
pointer is argc; the words beyond that are the zeroth and subsequent elements of argv, followed by a terminating null pointer; and the
return register (e.g. R0 on the 68020) contains the address of the clock.
Alef
In Alef, the intent and syntax are the same but the implementation is different. Exec (or execl; this description applies to either) may
be called only by a proc holding a single task, typically the implicit main task of the proc. First, access(2) is called to see if the
named file exists and has execute permission. If not, exec returns -1 immediately. Otherwise, it will never return: it frees resources
private to the invoking proc and calls the exec system call. If this fails, it calls the bare _exits system call (see exits(2)) with the
error string as argument. Therefore, if the file looks executable, the calling process is lost, whether the exec succeeds or not.
SOURCE
/sys/src/libc/9syscall
/sys/src/libc/port/execl.c
SEE ALSO
intro(2), stat(2)
DIAGNOSTICS
If these functions fail, they return and set errstr. There can be no return from a successful exec or execl; the calling image is lost.
EXEC(2)