我有一个使用ContentProvider类的应用程序.在openFile方法中,我需要能够解码文件并作为数据流返回.所以我决定使用内置管道.
问题是如果我使用createPipe方法,我只能写入64KB.之后我无法将数据写入管道.另请注意,在数据完全解码并写入管道之前,我无法读取.
package com.aujas.html.viewer.content;
public class LocalFileContentProvider extends ContentProvider {
private static final String URI_PREFIX = "content://com.aujas.html.viewer.localfile.dec/";
public static File file;
public String filename;
public ParcelFileDescriptor[] parcels;
public static String constructUri(String url) {
String editString = url.replaceAll("%20", " ");
int n = editString.length();
String uri = editString.substring(5, n - 1);
Log.d("URI", uri);
return URI_PREFIX + uri + "\"";
}
public ParcelFileDescriptor openFile(Uri uri, String mode) {
Log.d("OPEN", uri.getPath());
return parcels[0];
}
@Override
public boolean onCreate() {
return true;
}
@Override …Run Code Online (Sandbox Code Playgroud) 在Windows上我有一个从stdin读取的程序(prog.exe).在python中我想管道一个字符串作为其stdin的输入.怎么做?
就像是:
subprocess.check_output("echo {0} | myprog.exe".format(mystring))
Run Code Online (Sandbox Code Playgroud)
或者(使args成为一个列表)
subprocess.check_output("echo {0} | myprog.exe".format(mystring).split())
Run Code Online (Sandbox Code Playgroud)
似乎不起作用.它给了我:
WindowsError: [Error 2] The system cannot find the file specified
Run Code Online (Sandbox Code Playgroud)
我还尝试使用StringIO的"stdin"关键字arg(这是一个类似文件的对象)
subprocess.check_output(["myprog.exe"], stdin=StringIO(mystring))
Run Code Online (Sandbox Code Playgroud)
仍然没有运气 - check_output不适用于StringIO.
我正在尝试使用ffmpeg从mp3获取PCM数据,但文件存储在数据库gridfs中,所以我试图使用管道为ffmpeg提供一些成功的数据,但是有一个文件,ffmpeg处理correctlt如果用文件名作为输入,并且在将文件作为管道给出时不正确:(任何想法为什么?
ffmpeg -i - -f s16le -acodec pcm_s16le output.raw < testMp3s/test-corrupt.mp3
Run Code Online (Sandbox Code Playgroud)
给
ffmpeg version 0.11.1 Copyright (c) 2000-2012 the FFmpeg developers
built on Jun 9 2012 13:50:13 with gcc 4.7.0 20120505 (prerelease)
configuration: --prefix=/usr --enable-libmp3lame --enable-libvorbis --enable-libxvid -- enable-libx264 --enable-libvpx --enable-libtheora --enable-libgsm --enable-libspeex -- enable-postproc --enable-shared --enable-x11grab --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libschroedinger --enable-libopenjpeg --enable-librtmp --enable-libpulse --enable-libv4l2 --enable-gpl --enable-version3 --enable-runtime-cpudetect -- disable-debug --disable-static
libavutil 51. 54.100 / 51. 54.100
libavcodec 54. 23.100 / 54. 23.100
libavformat 54. 6.100 / 54. 6.100
libavdevice 54. …Run Code Online (Sandbox Code Playgroud) 如何使用STANDARD UNIX UTILITIES编写程序,该程序将一次从标准输入一个字符读取数据,并将结果输出到标准输出.我知道它的运行类似于本例中的C程序.有人告诉我,这可以在一行代码中完成,但从未完成过Unix管道编程,所以我只是很好奇.该程序的目的是从标准输入读取数据并计算一行中的行数和标准输出中的单词和行的总数
我想出了以下代码,但我不确定:
tr A-Z a-z < file | tr -sc a-z | sort uniq -c wc '\n'
关于我如何得到我想要的任何想法或建议?
我的申请要求孩子,孩子执行新程序,父母写信给孩子,然后在孩子完成一些工作后从孩子那里读回来.在监视管道的读取结束时,程序仍然在等待孩子.我目前没有写回父母,所以它故意阻止.下面是代码(write_to()函数关闭函数中管道的未使用部分):
pid_t leaf_proc;
int rv = 0;
int w_pfd[2];
int r_pfd[2];
if(pipe(w_pfd) == -1 || pipe(r_pfd) == -1){
printf("Failed to pipe. Goodbye.\n");
exit(0);
}
if((leaf_proc = fork()) < 0){
printf("Error: %s\n",strerror(errno));
exit(0);
}else if(leaf_proc == 0){
/***Child to be execl()'d***/
rv = execl("Some program");
if(rv < 0){
printf("Error: %s\n",strerror(errno));
exit(0);
}
}else{
/***Parent***/
write_to(par_info,w_pfd);
fd_set read_set;
//struct timeval tv;
//tv.tv_sec = 5;
//tv.tv_usec = 0;
FD_ZERO(&read_set);
FD_SET(r_pfd[0], &read_set);
rv = select(r_pfd[0]+1,&read_set,NULL,NULL,&tv);
printf("set?: %d\n",rv);
}
Run Code Online (Sandbox Code Playgroud)
运行此程序时,程序仍然在select语句中挂起(永远不会到达最后一个printf),但如果我添加超时信息,程序将在5秒后继续.首先,我正确使用选择吗?第二,虽然这可能不是阻塞(在某种意义上,父进程不会被内核中断,它是否仍会导致结果(进程挂起,直到某些东西准备好)?
我需要创建很多管道,我想在同一进程中的线程之间使用它们作为fifo队列,然后对它们进行选择/轮询.
我的问题是,如果我创建了很多队列,这会对程序的性能产生很大影响吗?管道数限制,资源消耗等
谢谢!
我想将.txt文件从命令行重定向到用D编写的exetuable.
$ ./myprogram < data.txt
Run Code Online (Sandbox Code Playgroud)
此文本文件由我要打印到屏幕的数字组成.到目前为止,我的程序包括:
import std.stdio, std.file;
void main(string[] args) {
string file = args[2];
writeln(read(file));
}
Run Code Online (Sandbox Code Playgroud)
但这不正确; 有人可以解释一下重定向的工作方式以及如何将数据传输到我的D程序中吗?
我正在尝试执行以下命令,
ls | grep "SOMETHING"
用c编程语言编写.任何人都可以帮助我.
我想分叉一个孩子,我将使用execlp运行ls命令.在父级中,我得到了孩子和grep的输出(再次使用execlp).
这不可能吗?
这就是我在看的:
echo "A B C D E F G H I" | java Subset 3
我真的不明白这里有什么|或echo意味着什么.在阅读了一些堆栈溢出线程之后,我知道由于命令行参数不会转到System.in,echo有助于将它放在那里吗?(我对此真的有一个非常模糊的想法),并且|命令将"每个参数""逐个"提供给程序?
这很有吸引力,但是当我尝试在eclipse调试器中测试它们时,这就是我得到的:

我期待一些特别的东西,但所有部分都只是像任何正常的论点那样去args [].这有点令人困惑.
大家好:这就是我要做的......拿一个结果集(例如listoffailedcomputers.txt)并对结果集中的每个项目运行一个复制命令.逻辑是在failedlistofcomputers.txt中的所有计算机上运行复制命令,以便最终结果将该文件夹本地复制到该列表上的所有计算机上.我可以通过在所有这些计算机上使用远程控制台来实现这一点,但这样做效率不高.谢谢.
这是我到目前为止写的代码.......
$failedcomputers = gc c:\listoffailedcomputers.txt
foreach ($failedcomputer in $failedcomputers)
{
$failedcomputer | copy-item \\server\patch\*.* -destination c:\patch\
}
Run Code Online (Sandbox Code Playgroud)
这就是我得到的错误......
Copy-Item : The input object cannot be bound to any parameters for the command
either because the command does not take pipeline input or the input and its
properties do not match any of the parameters that take pipeline input.
At copypatchtofailedcomputers.ps
+ $failedcomputer | copy-item <<<< \\server\patch\ -destination c:\patch\
+ CategoryInfo : InvalidArgument: (mycomputername:PSObject) [Copy-
Item], …Run Code Online (Sandbox Code Playgroud)