Executing two commands at a time

Hello everyone,
Basically I am a Android Developer and have a basic knowledge on C++
I am making a program to execute logcat on Android phone but I am stuck at a point
Before proceeding further, here is my partial source code
1
2
3
4
5
cout<<"Executing logcat on your phone"<<endl;
cout<<"Press any key when you want to stop execution of logcat"<<endl;
system("adb\\adb logcat > ../log.txt");
getch();
system("adb\\adb kill-server");

So now problem is, Program goes on executing and saving logcat forever and never moves to getch(); command to stop it, so how should I stop the logcat?
Is one command to check if user press a key and an other to collect the logcat can be worked out?


I tried a second alternative separately that if we press ctrl+c then logcat stops but in compiled program if ctrl+c is pressed then the program too gets closed

Any help is appreciated
logcat would need to have it's own way to be accessed by other programs. I don't know of the technical terms. There might be a possibility with threads. Start logcat on it's own thread, and possibly pause the thread when someone presses a button? I'm not 100% sure on threads and implementing them into programs, but might give you something to look into.
Can you give me very simple example on multithreaded C++ console application
Or is there any way to avoid termination of program with CTRL+C?
I don't know of a way to avoid the CTRL + C exit code simply because it's a console feature. As for the multithreading, the is so many ways to do it. It's a new standard as of the C++11 standard, and if you're using an old compiler, it may not have it. Alternatives would be the boost libraries which work similarly to the standard ones.
Yes but he is using Code::Blocks and GNU GCC Compiler which is a quite old (compared to other) so I'm not sure that the 2011 standard is implanted in it...

However, Volatile Pulse learn me something because I never heard about a multithread option in C++, thanks !!!
I personally use the Code::Blocks/GCC Compiler, and it supports many of the new C++11 features. As I said earlier, I have no implemented threads yet in any of my programs and am not 100% sure my version supports them, but I believe it does. I was also unaware of the compiler/IDE/OS the OP was using, so I didn't want to be too quick and assume.

As for references on the new standard, here is one at cppreference. The references here need updated badly.
http://en.cppreference.com/w/cpp/thread/thread

And here is a very simple explanation/walkthrough on starting with threads. I haven't found much on them yet since they're still fairly new and from what I've been told, a tutorial can't quite cover enough information to be effective.
http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=422

I would suggest at least seeing if the compiler supports threading by just including the <thread> header. You will receive an error if the library doesn't exist. (Don't forget you may need to include a compiler flag to enable the C++0x/C++11 features including std::thread)
Topic archived. No new replies allowed.