LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-17-2011, 05:59 AM   #1
endof
LQ Newbie
 
Registered: Nov 2009
Location: Turkey
Distribution: Ubuntu
Posts: 4

Rep: Reputation: 0
popen("motion")


FILE *fp;
char path[1035];
fp = popen("motion", "r");
while (fgets(path, sizeof(path)-1, fp) != NULL) {
cout<<path;
ui->textBrowser->append(path);
}
pclose(fp);

no output
or terminal
root@D630:~# motion > motion.txt
motion.txt empty


ı need output motion program please help me
 
Old 05-17-2011, 06:25 AM   #2
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,507

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Please post code within CODE tags, so that the code indentation is preserved. (Please re-edit your post to add formatted code).

As for popen(), it is meant to invoke a command. It would seem the command you want to invoke is the same as the name of the executable that is calling popen()? Is this what you really want?

Here's a working example of using popen():
Code:
#include <cstdio>
#include <iostream>

int main()
{
   FILE* fp = popen("/sbin/ifconfig eth0", "r");

   if (fp)
   {
      char buf[1024];

      while (fgets(buf, sizeof(buf), fp))
      {
         std::cout << buf << std::endl;
      }

      pclose(fp);
   }
   else
   {
      std::cerr << "Cannot execute /sbin/ifconfig." << std::endl;
      return -1;
   }
   return 0;
}
P.S. You should avoid developing s/w under the root account.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
use of "man [page] | col -b" with popen(); mk27 Linux - General 0 09-26-2008 01:36 PM
popen on Linux redhat4.5 doesn't take "rw" ? nano2 Programming 2 03-07-2008 10:31 AM
Error with "SDL_MouseMotionEvent *motion = event->motion;" aatwell Programming 3 11-30-2007 01:46 PM
Finding pid of a process opened by "popen" Guttorm Programming 2 03-12-2007 02:35 PM
music/sound in general plays in "slow motion" tvstonydanza Linux - General 0 01-29-2004 07:29 PM


All times are GMT -5. The time now is 04:07 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration