Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Linux cµÄpopen()

½ø³ÌI/Oº¯Êý,Óëpcloseº¯ÊýÒ»ÆðʹÓá£
±íÍ·Îļþ
¡¡¡¡#include <stdio.h>
º¯Êý¶¨Òå
¡¡¡¡FILE * popen
( const char * command
, const char * type
);
¡¡¡¡int pclose
( FILE * stream
);
º¯Êý˵Ã÷
¡¡¡¡
popen() º¯Êýͨ¹ý´´½¨Ò»¸ö¹ÜµÀ£¬µ÷Óà fork ²úÉúÒ»¸ö×Ó½ø³Ì£¬Ö´ÐÐÒ»¸ö shell ÒÔÔËÐÐÃüÁîÀ´¿ªÆôÒ»¸ö½ø³Ì¡£Õâ¸ö½ø³Ì±ØÐëÓÉ
pclose() º¯Êý¹Ø±Õ£¬¶ø²»ÊÇ fclose() º¯Êý¡£pclose() º¯Êý¹Ø±Õ±ê×¼ I/O Á÷£¬µÈ´ýÃüÁîÖ´ÐнáÊø£¬È»ºó·µ»Ø shell
µÄÖÕֹ״̬¡£Èç¹û shell ²»Äܱ»Ö´ÐУ¬Ôò pclose() ·µ»ØµÄÖÕֹ״̬Óë shell ÒÑÖ´ÐÐ exit Ò»Ñù¡£
¡¡¡¡ type
²ÎÊýÖ»ÄÜÊǶÁ»òÕßдÖеÄÒ»ÖÖ£¬µÃµ½µÄ·µ»ØÖµ£¨±ê×¼ I/O Á÷£©Ò²¾ßÓÐºÍ type ÏàÓ¦µÄÖ»¶Á»òֻдÀàÐÍ¡£Èç¹û type ÊÇ "r" ÔòÎļþÖ¸ÕëÁ¬½Óµ½ command µÄ±ê×¼Êä³ö£»Èç¹û type ÊÇ "w" ÔòÎļþÖ¸ÕëÁ¬½Óµ½ command µÄ±ê×¼ÊäÈë¡£
¡¡¡¡ command
²ÎÊýÊÇÒ»¸öÖ¸ÏòÒÔ NULL ½áÊøµÄ shell ÃüÁî×Ö·û´®µÄÖ¸Õë¡£ÕâÐÐÃüÁ±»´«µ½ bin/sh ²¢Ê¹ÓÃ-c ±êÖ¾£¬shell ½«Ö´ÐÐÕâ¸öÃüÁî¡£
¡¡¡¡ popen
µÄ·µ»ØÖµÊǸö±ê×¼ I/O Á÷£¬±ØÐëÓÉ pclose
À´ÖÕÖ¹¡£Ç°ÃæÌáµ½Õâ¸öÁ÷Êǵ¥ÏòµÄ¡£ËùÒÔÏòÕâ¸öÁ÷дÄÚÈÝÏ൱ÓÚдÈë¸ÃÃüÁîµÄ±ê×¼ÊäÈ룻ÃüÁîµÄ±ê×¼Êä³öºÍµ÷Óà popen
µÄ½ø³ÌÏàͬ¡£ÓëÖ®Ïà·´µÄ£¬´ÓÁ÷ÖжÁÊý¾ÝÏ൱ÓÚ¶ÁÈ¡ÃüÁîµÄ±ê×¼Êä³ö£»ÃüÁîµÄ±ê×¼ÊäÈëºÍµ÷Óà popen
µÄ½ø³ÌÏàͬ¡£
·µ»ØÖµ
¡¡¡¡ Èç¹ûµ÷Óà fork() »ò pipe() ʧ°Ü£¬»òÕß²»ÄÜ·ÖÅäÄڴ潫·µ»ØNULL£¬·ñÔò·µ»Ø±ê×¼ I/O Á÷¡£
·µ»Ø´íÎó
¡¡¡¡ popen
ûÓÐΪÄÚ´æ·ÖÅäʧ°ÜÉèÖà errno Öµ¡£
¡¡¡¡Èç¹ûµ÷Óà fork() »ò pipe() ʱ³öÏÖ´íÎó£¬errno ±»ÉèΪÏàÓ¦µÄ´íÎóÀàÐÍ¡£
¡¡¡¡Èç¹û type ²ÎÊý²»ºÏ·¨£¬errno½«·µ»ØEINVAL¡£
ʹÓþÙÀý
¡¡¡¡ if((fp=popen("/usr/bin/uptime","r"))==NULL);
¡¡¡¡{
¡¡¡¡sprintf(buf,"error: %s\n", strerror(errno));
¡¡¡¡....//Òì³£´¦Àí
¡¡¡¡}
¡¡¡¡else
¡¡¡¡{
¡¡¡¡....
¡¡¡¡pclose(fp);
¡¡¡¡}


Ïà¹ØÎĵµ£º

wince±³¹âµ÷½Ú VC´úÂëcÎļþ

// backlightDlg.cpp : implementation file
//
#include "stdafx.h"
#include "backlight.h"
#include "backlightDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CbacklightDlg dialog
CbacklightDlg::CbacklightDlg(CWnd* pParent /*=NULL*/)
 : CDialog(CbacklightDlg::IDD, pParent)
{
  ......

ºÇºÇ£¡Ò»¸öQTͨ¹ýÌùͼʵÏÖµÄÄ£ÄâʱÖÓ cÎļþ

#include "draw.h"
#include "ui_draw.h"
#include <QPixmap>
draw::draw(QWidget *parent)
    : QDialog(parent), ui(new Ui::draw)
{
    ui->setupUi(this);
//    this->setWindowFlags( Qt::FramelessWindowHint);
    ctrlPoint.s ......

Çó½Ì¸ßÊÖ ¹ØÓÚC²¥·ÅwavÎÊÌâ


×î½üÔÚÍøÉϲéÁ˺öà¹ØÓÚC²¥·ÅwavÕâ·½ÃæµÄ×ÊÁÏ£¬µ÷ÊÔ°ëÌìҲûÓнá¹û£¬Ëѵ½Ò»¸ö±àÒëºÃµÄEXEÎļþÄܲ¥·Å£¬Ã»ÓÐÔ´´úÂ룬·´»ã±à²»ÁË£¬Ë­ÄÜÖ¸µãһϡ£¡£¡£¡£¡£ÒÔÏÂÁ½ÖÖ´úÂë¶Î£º
 #include <stdio.h>
#include <dos.h>
/* wavÎļþ½á¹¹ */
typedef struct WaveData
{
   unsigned long sample_le ......

¶¨ÒåC/C++È«¾Ö±äÁ¿/³£Á¿¼¸ÖÖ·½·¨µÄÇø±ð

ÔÚÌÖÂÛÈ«¾Ö±äÁ¿Ö®Ç°ÎÒÃÇÏÈÒªÃ÷°×¼¸¸ö»ù±¾µÄ¸ÅÄ
 
1. ±àÒëµ¥Ôª(Ä£¿é)£º
    ÔÚIDE¿ª·¢¹¤¾ß´óÐÐÆäµÀµÄ½ñÌ죬¶ÔÓÚ±àÒëµÄһЩ¸ÅÄîºÜ¶àÈËÒѾ­²»ÔÙÇå³þÁË£¬ºÜ¶à³ÌÐòÔ±×îŵľÍÊÇ´¦ÀíÁ¬½Ó´íÎó(LINK ERROR), ÒòΪËü²»Ïñ±àÒë´íÎóÄÇÑù¿ÉÒÔ¸ø³öÄã³ÌÐò´íÎóµÄ¾ßÌåλÖã¬Äã³£³£¶ÔÕâÖÖ´íÎó¸Ðµ½°ÃÄÕ£¬µ«ÊÇÈç¹ûÄã¾ ......

¹ØÓÚdelete C/C++ Ö¸Õë

Õ»£ºº¯Êýµ÷ÓõÄʱºò£¬ÔÚÕ»Öб£´æ¾Ö²¿±äÁ¿ºÍº¯Êý²ÎÊýµÈ¡£µ±º¯Êý·µ»Øʱ£¬×Ô¶¯Çå³ýÕ»¡£
×ÔÓÉ´æ´¢Çø£ºÒ²³ÆΪ¶Ñ(heap)£¬¿ÉÒÔ¿´×÷´óÁ¿µÄÄÚ´æ¶Î¡£Í¨¹ý new ²Ù×÷·û·ÖÅäµÄÄÚ´æÔÚ¶ÑÖС£³ÌÐò½áÊø֮ǰ²»×Ô¶¯Çå³ý×ÔÓÉ´æ´¢Çø¡£ÐèÒªÓɳÌÐòÀ´¸ºÔðÊÍ·Å£¨delete£©¡£
1.
¶ÔÖ¸ÏòÕ»ÉÏÄÚ´æµÄÖ¸Õëµ÷ÓÃdelete»áµ¼Ö³ÌÐòCrash¡£
2. 
new ½ø ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ