Hello,
I have a c program executable which I need to run inside a shell script.
But the c program runs in a subshell because of which all the actions done by the c program is not available to the current shell.
Is there any way to execute a C program binary executable in the current shell?
There is no way to execute a compiled executable within a shell. Shells execute shell scripts, not binaries. If you need a side effect of a child process on the parent shell, your compiled program could output shell commands, which are intercepted and executed by the parent shell (sort of eval :-) )
For example, if the compiled program prints the following output to stdout:
and the shell starts the program like
the shell will define the two variables ABC and DEF and change the current working directory to /tmp.
Last edited by hergp; 04-09-2013 at 04:55 AM..
Reason: semicolons added
Hello,
I have a c program executable which I need to run inside a shell script.
But the c program runs in a subshell because of which all the actions done by the c program is not available to the current shell.
Is there any way to execute a C program binary executable in the current shell?
If a C program needs to export some variables, things usually work the opposite way -- run your C program first, export a bunch of variables, then run your program. Your program will inherit the new values from it that way.
Is there any way to execute a C program binary executable in the current shell?
You should explain why you want it to be run by the current shell.
In any case, if you have the source code of your program and if your shell is ksh93, there is a way to modify your program to make it a custom builtin command and then have it effectively running by the current shell, see www/ksh/builtins.mm mm document
If your only goal is to set variables, that would be overkill compared to the previous suggestions though.
Hi All,
well , i am facing this problem.. i have tried a few sample codes but there isn't any solution . could anyone please give a sample code as of how to do this...
Please see the below details...and read the details carefully.
I have written some code, logic is
1)from... (4 Replies)
I want to add a crontab entry which should execute for every 4 hours and that 4 hours calculation should begin from the current time.
Normally if I set the crontab entry like this,
00 */4 30 05 * root date >>/tmp/cronout
The above will execute the date command for every 4 hours like... (7 Replies)
Hi
I want to create a shell script tha executes a C program and then retrieves information about it.
I managed to run the program with:
#!/bin/bash
gcc -o program program.c
./program
Now i want to get the id of the process (pid)
Any help would be appreciated,
Thank you (18 Replies)
I have a file as follows:
cat /etc/mxg/ssh-hostsmx.example1.com.au:2225
mx2.example2.com.au:2225
mx.example3.com.au:2225
mail.example4.com.au:2225
mail.example5.org.au:2225
mail.example6.com.au:2225I want to dynamically create aliases for quick access to these servers from bash. I wrote... (4 Replies)
How does the program know the full path of itself when the program is running in certain diretory? BTW, I have no "argv" information of main() functino.
(The program is written in C++ on linux platform) (1 Reply)
Hi,
i want to write a script that executes a program (exec?) .
this program then requires a filename as input.
how do i give it this input in the script so the program will be complete run and close by the script.
e.g.
exec prog.exe
program then asks for filename
"enter filename:"... (1 Reply)
How do i run a shell script or perl script with in the context of a current shell.
I know that i can use command source. but we can't pass any arguments to
our script if we use source command as it takes only one argement i.e filename
Is there any way to run a script in the current shell... (5 Replies)
hi,
I am new ot unix. So, can i write a shell(c shell or korn shell) program to access internet? I mean if I run the program, it can access specified url and then copy the html to a file? Can anyone help me? And how can make the program runs every 1 hr?
new comer (2 Replies)