Hello, I'm currently implementing the && function in a shell using C. For example, if we input cmd1 && cmd2, then cmd2 executes only when cmd1 exits successfully. I'm thinking about:
So I'm using another function int execute(char ** args) to do the actual work. Its return type is int because I wan to know whether the command exits successfully. But I'm not sure here whether the parent process can get the return value from the child since they're two different processes.
Or should I decide whether to execute the second command in the child process, by forking another process to run it? Thanks a lot.
Hello all,
Can someone explain to me the advantage between using subshell over a function call in scripts? To me these are the same. Am I wrong to think this? (4 Replies)
Hi,
If this is the array that is being returned to me:
How would I get the values for each of the 3 records?
This works for 1 Record:
foreach $item (@results)
{
($id, $id2, $name, $date, $email) = split(/\|/, $item, 5);
print "$name<br>";
} (2 Replies)
I am going to take up a position in Data & Network Security.
I would need to write network shell scripts doing the following task:
Going to around 2000 servers and findout which groups has access to each servers and which ids are there in each group that has access.
I need to implement... (1 Reply)
Hello to all,
I am looking for a way to display only the names of function (calls & definition) of a C++ source code.There is already a post related to this, but the script is to find the functions using a specific variable, and the replies are not that convincing since they cannot be used for... (2 Replies)
Hi, I hope the title does not scare people to look into this thread but it describes roughly what I'm trying to do. I need a solution in PHP.
I'm a programming beginner, so it might be that the approach to solve this, might be easier to solve with an other approach of someone else, so if you... (0 Replies)
Hello All
I have a xml file with many sets of records
like this
<mytag>mydata</mytag>
<tag2>data&</tag2>
also same file can be like this
<mytag>mydata</mytag>
<tag2>data&</tag2>
<tag3>data2&data3</tag3>
Now i can grep & and replace with & for whole file but it will replace all... (4 Replies)
Hi, I have text file abc.txt. In this file, I have the following data.
Input:
Mr Smith & Mrs Smith
Mr Smith &apos Mrs Smith
Mr Smith & Mrs Smith
Mr Smith& Mrs Smith
Mr Smith &Mrs Smith
Output:
Mr Smith & Mrs Smith
Mr Smith &apos Mrs Smith
Mr Smith & Mrs Smith
Mr Smith&... (4 Replies)
How to use MAN to find information about read() and write() function ?
The command "man read" show some rubbish, for example "man open" show great information about function I need. (2 Replies)
Hi All,
Do you have any sample script,
- auto get file from SFTP remote server and delete file in remove server after downloaded.
- only download specify filename
- auto upload file from local to SFTP remote server and delete local folder file after uploaded
- only upload specify filename
... (3 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
2. Relevant commands, code, scripts, algorithms:
#! /bin/ksh
v="ORG_ID"
... (2 Replies)
Discussion started by: sujitdas2104
2 Replies
LEARN ABOUT DEBIAN
proc::syncexec
SyncExec(3pm) User Contributed Perl Documentation SyncExec(3pm)NAME
Proc::SyncExec - Spawn processes but report exec() errors
SYNOPSIS
# Normal-looking piped opens which properly report exec() errors in $!:
sync_open WRITER_FH, "|command -with args" or die $!;
sync_open READER_FH, "command -with args|" or die $!;
# Synchronized fork/exec which reports exec errors in $!:
$pid = sync_exec $command, @arg;
$pid = sync_exec $code_ref, $cmd, @arg; # run code after fork in kid
# fork() which retries if it fails, then croaks() if it still fails.
$pid = fork_retry;
$pid = fork_retry 100; # retry 100 times rather than 5
$pid = fork_retry 100, 2; # sleep 2 rather than 5 seconds between
# A couple of interfaces similar to sync_open() but which let you
# avoid the shell:
$pid = sync_fhpopen_noshell READERFH, 'r', @command;
$pid = sync_fhpopen_noshell WRITERFH, 'w', @command;
$fh = sync_popen_noshell 'r', @command_which_outputs;
$fh = sync_popen_noshell 'w', @command_which_inputs;
($fh, $pid) = sync_popen_noshell 'r', @command_which_outputs;
($fh, $pid)= sync_popen_noshell 'w', @command_which_inputs;
DESCRIPTION
This module contains functions for synchronized process spawning with full error return. If the child's exec() call fails the reason for
the failure is reported back to the parent.
These functions will croak() if they encounter an unexpected system error, such as a pipe() failure or a repeated fork() failure.
Nothing is exported by default.
fork_retry [max-retries [sleep-between]]
This function runs fork() until it succeeds or until max-retries (default 5) attempts have been made, sleeping sleep-between seconds
(default 5) between attempts. If the last fork() fails fork_retry croak()s.
sync_exec [code] command...
This function is similar to a fork()/exec() sequence but with a few twists.
sync_exec does not return until after the fork()ed child has already performed its exec(). The synchronization this provides is useful
in some unusual circumstances.
Normally the pid of the child process is returned. However, if the child fails its exec() sync_exec returns undef and sets $! to the
reason for the child's exec() failure.
Since the @cmd array is passed directly to Perl's exec() Perl might choose to invoke the command via the shell if @cmd contains only
one element and it looks like it needs a shell to interpret it. If this happens the return value of sync_exec only indicates whether
the exec() of the shell worked.
The optional initial code argument must be a code reference. If it is present it is run in the child just before exec() is called.
You can use this to set up redirections or whatever. If code returns false no exec is performed, instead a failure is returned using
the current $! value (or EINTR if $! is 0).
If the fork() fails or if there is some other unexpected system error sync_exec croak()s rather than returning.
sync_fhpopen_noshell fh type cmd [arg]...
This is a popen() but it never invokes the shell and it uses sync_exec() under the covers. See "sync_exec".
The type is either 'r' to read from the process or 'w' to write to it.
The return value is the pid of the forked process.
sync_popen_noshell type cmd arg...
This is like sync_fhpopen_noshell, but you don't have to supply the filehandle.
If called in an array context the return value is a list consisting of the filehandle and the PID of the child. In a scalar context
only the filehandle is returned.
sync_open fh [open-spec]
This is like a Perl open() except that if a pipe is involved and the implied exec() fails sync_open() fails with $! set appropriately.
See "sync_exec".
Like sync_exec, sync_open croak()s if there is an unexpected system error (such as a failed pipe()).
Also like sync_exec, if you use a command which Perl needs to use the shell to interpret you'll only know if the exec of the shell
worked. Use sync_fhpopen_noshell or sync_exec to be sure that this doesn't happen.
AUTHOR
Roderick Schertler <roderick@argon.org>
SEE ALSO perl(1).
perl v5.8.8 2005-02-04 SyncExec(3pm)