甚至可以将execl的命令行参数从C传输到bash吗?因为C到C文件我得到了exect formatt错误。所以决定尝试使用C main,并使用bash son脚本,一切运行正常,除了我无法弄清楚如何使用execl传输argv,而不是将其与儿子一起使用..
FATHER
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
main( int argc, char *argv[])
{
int pid;
if (argc==4)
{
printf ("Need to enter 3 arguments");
printf ("\tOne Process yet, creating second...\n");
pid = fork();
}
else
{
printf ("Need to give me 3 arguments\n");
exit(EXIT_FAILURE);
}
if(pid==0)
{
printf("\tChild process launched...\n");
execl("./testB", "testB", argv[1], argv[2], argv[3], NULL);
perror("execl dissapointed us");
}
else if(pid>0)
{
printf ("\twaiting for my child to finish...\n");
wait((int *)0);
printf("\t Child finished, time for father...\n");
printf("Main Father\n");
}
else
{
printf("We've got an error, boss\n");
}
printf("Two proccesses?\n");
printf("Number of arguments %d", argc);
}
SON
#!/bin/bash
printf "im da testB\n"
echo "Iveskite norima kieki konvertacijai"
read litai
while [ "$litai" -le 0 ]
do
echo "Iveskite norima kieki konvertacijai"
read litai
done
SUM=$( echo "scale=4;$litai*3.4528" | bc )
printf "Jusu pasirinktas litu kiekis %d atitinka %s eurus\n" "$litai" "$SUM"
printf "asd %s\n" "$argv[1]"