![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| passing variable from bash to perl from bash script | arsidh | Shell Programming and Scripting | 10 | 06-04-2008 09:25 AM |
| Why generate "ash and bash" different output for same bash script? | s. murat | Shell Programming and Scripting | 0 | 05-26-2008 04:19 AM |
| Bash under AIX 5.3 | taupin | AIX | 4 | 03-21-2008 03:03 AM |
| Bash: how to do it? | sopel39 | Shell Programming and Scripting | 3 | 11-02-2007 01:35 AM |
| Bash it! Bash it! | SoulForge | Shell Programming and Scripting | 5 | 11-22-2002 10:02 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Bash in C ?
Hi friends,Can iuse Bash commands in my C programs,like that
if((cd /root/Desktop/) == true) do somethig. I have to control a variable called path,i want to know,this path is in Unix Directories or not,Is there anybody help me?, Thank you.. ***email address removed by moderator -- reborg Last edited by reborg; 02-02-2007 at 04:47 PM. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
1. most commands are also found in the C library
remove() = rm chdir() = cd ... etc. 2. You can execute shell commands in C using two methods: A. system() Code:
system("rm -f somefile");
Code:
#include <stdio.h>
..........
FILE *cmd=popen(" find . -type -f -print","r");
char tmp[256]={0x0};
while (fgets(tmp,sizeof(tmp),cmd)!=NULL)
{
printf("%s\n", tmp);
}
pclose(cmd);
|
|
#3
|
|||
|
|||
|
yes i try what you said,and it works,thank you jim mcnamara,
but i dont know,can we use our variables in system function like that?, #include <stdio.h> main() { char *path; path = "/usr/bin/"; if(system("cd 'path'")==0) -------------------- ? my variable in do; else go; } thank you very much again, |
|
#4
|
|||
|
|||
|
Code:
char cmd[80]={0x0};
char *path="/path/to/somewhere";
sprintf(cmd,"cd %s", path);
system(cmd);
Use chdir() instead if you want the program to actually change working directories. |
|||
| Google The UNIX and Linux Forums |