mplayer 突然不喜欢 popen 了吗?

mplayer doesn't like popen suddenly?

几天来一直被 popen 的问题难倒。

代码:

int main(){
 FILE *fp = popen("mplayer /home/linaro/Music/cp.mp3", "r");
char buffer[1028]; 
while (fgets(buffer, 1028, fp) != NULL) 
{ 
  std::cerr<<buffer; 
} 
pclose(fp);
fp = 0;
return 0;

}

在商店里 运行 使用了 linaro 嵌入式控制器。 运行 很好,没有错误。尽管代码很简单(只是在执行时播放一首酷玩歌曲然后退出),但它似乎给我带来了比想象中更多的悲伤。

如果我将命令本身复制并粘贴到普通 bash shell,它 运行 没问题。更糟糕的是,它是否 运行 很好,直到它被插入其他地方。我不确定它现在是通过耳机插孔连接还是之前是通过线路输出插孔连接。

无论如何,当我 运行 时得到的错误是(总结到相关部分)

MPlayer svn r34540 (Ubuntu), built with gcc-4.6 (C) 2000-2012 MPlaye4

Team mplayer: could not connect to socket mplayer: No such file or

directory Failed to open LIRC support. You will not be able to use

your remote control.

Playing /home/linaro/Music/cp.mp3 libavformat version 53.21.1

(external) Mismatching header version 53.19.0 Audio only file format

detected. Clip info: Title: The Scientist Artist: Coldplay Album: A

Rush Of Blood To The Head Year: 2002 Comment: Genre: Unknown Load

subtitles in /home/linaro/Music/ Requested audio codec family [mpg123]

(afm=mpg123) not available. Enable it at compilation. Opening audio

decoder: [ffmpeg] FFmpeg/libavcodec audio decoders libavcodec version

53.35.0 (external) Mismatching header version 53.32.2 AUDIO: 44100 Hz, 2 ch, floatle, 256.0 kbit/9.07% (ratio: 32002->352800) Selected audio

codec: [ffmp3float] afm: ffmpeg (FFmpeg MPEG layer-3 audio) Home

directory not accessible: Permission denied AO: [pulse] Init failed:

Connection refused Failed to initialize audio driver 'pulse' Home

directory not accessible: Permission denied [AO_ALSA] alsa-lib:

pcm_hw.c:1293:(snd_pcm_hw_open) open '/dev/snd/pcmC1D0p' failed (-22):

Invalid argument [AO_ALSA] Playback open error: Invalid argument

Failed to initialize audio driver 'alsa' [AO SDL] Samplerate: 44100Hz

Channels: Stereo Format floatle [AO SDL] using aalib audio driver. [AO

SDL] Unsupported audio format: 0x1d. [AO SDL] Unable to open audio: No

available audio device Failed to initialize audio driver 'sdl:aalib'

Could not open/initialize audio device -> no sound. Audio: no sound

Video: no video

同样,如果我将它通过 popen 执行的确切命令复制并粘贴到控制台,它就会开始播放。如果也通过 -ao alsa、-ao pulse、-ao oss,它会失败,这让我完全难住了。如有任何帮助,我们将不胜感激!

编辑: Linux 是 linaro,基于 Ubuntu 12.04 使用 arm CPU

问题正如 Jonas 和 alk 所建议的那样 -- 权限。一路走来改变了它的方式 运行,但在一天结束时,肮脏的修复只是包括

su - user -c ' mplayer ... '

到被叫线路。