我又用ls、locate 等命令试了,都能正常输出。看来问题是出在我那些程序上,在此谢谢上面两位给我的提示。另外:使用execute()执行时确实要在命令后面添加一个空格,不过怎么在linux命令行下没有那个空格也能正常重定向输出呢?仍旧不理解。
这些被测程序是TinyOS的程序,用nesc写的,大家不一定熟悉。问题可能与nesc的输出机制有关联吧。具体原因恐怕还需要进一步分析,尽管是输出到标准输出,但估计与Qt关系不大。
这里给大家一个TinyOS的例子:这个测试案例有三个程序,两个是nesc的,一个是python的:运行环境是ubuntu,另外还需要下载安装tinyos-2.x才能执行。有兴趣的可以安装tinyos2.x之后试试。
1.nesc程序BlinkC.nc:
#include "Timer.h"
module BlinkC @safe()
{
uses interface Timer<TMilli> as Timer0;
uses interface Timer<TMilli> as Timer1;
uses interface Timer<TMilli> as Timer2;
uses interface Leds;
uses interface Boot;
}
implementation
{
uint8_t counter = 0;
event void Boot.booted()
{
call Timer0.startPeriodic( 250 );
call Timer1.startPeriodic( 500 );
call Timer2.startPeriodic( 1000 );
dbg("Boot","Application booted \n");
dbg("Radio","Application booted again.\n");
counter ++;
}
event void Timer0.fired()
{
dbg("BlinkC", "Timer 0 fired @ %s.\n", sim_time_string()); //将输出定向到BlinkC通道,估计就是这里的问题。
call Leds.led0Toggle();
}
event void Timer1.fired()
{
dbg("BlinkC", "Timer 1 fired @ %s \n", sim_time_string());
call Leds.led1Toggle();
}
event void Timer2.fired()
{
dbg("BlinkC", "Timer 2 fired @ %s.\n", sim_time_string());
call Leds.led2Toggle();
}
}
2. nesc程序 BlinkAppC
/**
* Blink is a basic application that toggles the a mote LED periodically.
* It does so by starting a Timer that fires every second. It uses the
* OSKI TimerMilli service to achieve this goal.
*
* @author
tinyos-help@millennium.berkeley.edu**/
configuration BlinkAppC
{
}
implementation
{
components MainC, BlinkC, LedsC;
components new TimerMilliC() as Timer0;
components new TimerMilliC() as Timer1;
components new TimerMilliC() as Timer2;
BlinkC -> MainC.Boot;
BlinkC.Timer0 -> Timer0;
BlinkC.Timer1 -> Timer1;
BlinkC.Timer2 -> Timer2;
BlinkC.Leds -> LedsC;
}
3.python程序 tinysim.py
from TOSSIM import *
from tinyos.tossim.TossimApp import *
t = Tossim([])
m1 = t.getNode(1) //定义节点m1
m2 = t.getNode(2)
m3 = t.getNode(3)
f = open("log.txt","w")
t.addChannel("Boot",sys.stdout)
t.addChannel("Radio",f)
t.addChannel("BlinkC",sys.stdout) //向标准输出添加BlinkC通道
m1.bootAtTime(345221); //节点m1的启动时间
m2.bootAtTime(345222);
m3.bootAtTime(345223);
for i in range (0,100): //循环运行100次
t.runNextEvent()