Results 1 to 10 of 10
hi
i want to execute the history command in c wih this simple code but it dosnot show anything,any other solution..
Code:
#include <stdio.h>
main()
{
system("history > a.txt");
}
...
- 10-28-2010 #1Just Joined!
- Join Date
- Sep 2010
- Posts
- 14
problem with callig history command in c file
hi
i want to execute the history command in c wih this simple code but it dosnot show anything,any other solution..
my purpose is to write the history log file on a txt file with a c program..Code:#include <stdio.h> main() { system("history > a.txt"); }
pls help me if you have any idea..
thanks.
- 10-28-2010 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Where the history is stored depends upon the shell, and is different for each invocation of the shell. For the bash shell, look in the ~/.bash_history file.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 10-29-2010 #3Just Joined!
- Join Date
- Sep 2010
- Posts
- 14
i find ~/.bash_history but the problem is that i need the timestamp of each entry so i added this: export HISTTIMEFORMAT="%F %T " ,
this will show me the timestamp in the bash but the change is not applied to ~/.bash_history.it means that there is no timestamp in ./bash_history.
so that 's why i went for system("history > a.txt");
any possibility that i have timestamp in ~/.bash_history???
thanks..
- 10-29-2010 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Sorry, I don't know. I'd have to look at the bash source code to see exactly what is going on with history stuff. I don't see any time stamps in ~/.bash_history, but I tried the environment variable that you showed and it does output a timestamp along with the sequence number. I'm not sure how they are doing that unless it is coming from somewhere other than ~/.bash_history. Maybe one of the other lurkers here know and can comment?
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 10-29-2010 #5
Did you try this:
system('HISTTIMEFORMAT="%F %T " history > a.txt');
- 10-29-2010 #6Linux Newbie
- Join Date
- Mar 2010
- Posts
- 121
Has my post in t'other forum answered your question?
If your problem is resolved, please say so in any threads you have started so people don't waste their time trying to help you out.
- 11-01-2010 #7Just Joined!
- Join Date
- Sep 2010
- Posts
- 14
sorry,but i could not get my answer!!!
- 11-01-2010 #8
- 11-07-2010 #9Just Joined!
- Join Date
- Jan 2010
- Posts
- 27
I've run shell builtin called "set" and it revealed essential differences between the shell I work and the (probably temporary) shell instance used by system().
First difference is that HISTFILE variable gets lost. We need it to be recreated. I guess.
Second difference is here:
Amongst others, "history" option is missing from the SHELLOPTS variable. We need it to be set.Code:-SHELLOPTS=braceexpand:hashall:interactive-comments +SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
I didn't investigate further, just worked around it in a straight way:
Voila : )Code:system("HISTFILE=~/.bash_history; set -o history; HISTTIMEFORMAT='%F %T ' history");
- 11-08-2010 #10Just Joined!
- Join Date
- Sep 2010
- Posts
- 14


Reply With Quote
