Re: Calling ssh from C-Program with execvp



On 2007-01-21 19:28:38 +0100, "Richard E. Silverman" <res@xxxxxxxx> said:

---------------------------------------------------------------
#include <stddef.h>
#include <sys/types.h>
#include <sys/wait.h>

main () {
int status;
char *argv[] = {"ssh","remote_host","echo","foo",NULL};

if (fork()) {
wait(&status);
} else {
execvp("/usr/bin/ssh", argv);
}
}
---------------------------------------------------------------

Just a slight modification. The main function must return an int according to the standard, use:

int main(int argc, char* argv[])

or

int main(void)


And don't forget the return statement. Just my 2 cents to avoid undefined behaviors :)

--
Sensei <senseiwa@Apple's mail>

Research (n.): a discovery already published by a chinese guy one month
before you, copying a russian who did it in the 60s.

.



Relevant Pages

  • [BUG] Linux VM use-once mechanisms dont work (test case with numbers included)
    ... A file of 1/3 the RAM size is created, ... The test execution time greatly increase after reading or copying the ... int main ... void *buf; ...
    (Linux-Kernel)
  • Re: Accessing individual bytes of an integer
    ... copying byte by byte is ok in my book. ... The value representation of an object is the set of bits ... > Secondly, the standard guarantees that only memcpyworks in this case, and not copying it char by char or unsigned char by ... > int secondInteger; ...
    (comp.lang.cpp)
  • [PATCH 4/4] altix: msi support
    ... MSI callouts for altix. ... +sn_msi_teardown(unsigned int vector) ... * License. ... See the file "COPYING" in the main directory of this archive ...
    (Linux-Kernel)
  • [PATCH 2/3] altix: msi support
    ... MSI callouts for altix. ... +sn_msi_teardown(unsigned int vector) ... * License. ... See the file "COPYING" in the main directory of this archive ...
    (Linux-Kernel)
  • [PATCH 2/3] altix: msi support
    ... MSI callouts for altix. ... +sn_msi_teardown(unsigned int vector) ... * License. ... See the file "COPYING" in the main directory of this archive ...
    (Linux-Kernel)