I'm trying to re-write some of my shell scripts with C++ and I want to use some Unix commands, but I don't really get how, all the information on System() is just confusing to me...so any help would be great,
Subterraneus
0
Newbie Poster
Recommended Answers
Jump to Post>all the information on System() is just confusing to me
It's just a command interpreter. Pass it a string just like you would your shell and things will happen. :rolleyes: Intuitively, system is one of the simplest functions.
Jump to PostIf your commands produce output consider using popen() which works like somewhat system() but allows one-way communication between the shell and the C program.
system() does'nt do that.
man popen
Jump to Postsystem expects the memory address of an array af characters. Your code is not valid C++ syntax. You could write
system("echo 9");
. Or you could use a stringstream to build a string dynamically.std::ostringstream s(""); int x(9); s << "echo " << x; std::system(s.str().c_str());
All 9 Replies
Narue
5,707
Bad Cop
Team Colleague
jim mcnamara
19
Junior Poster
Subterraneus
0
Newbie Poster
Rashakil Fol
978
Super Senior Demiposter
Team Colleague
Subterraneus
0
Newbie Poster
dwks
149
Posting Whiz in Training
Subterraneus
0
Newbie Poster
Subterraneus
0
Newbie Poster
Subterraneus
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.