我正在开发我的库,它需要捕获和处理子进程运行时的标准输出(和错误)。当使用 ReadFile 读取输出时会出现问题,一旦进程结束(被杀死或退出),它就不会返回。
看起来ReadFile无法检测到管道的另一端(写入句柄)已关闭。根据文档,它应该返回FALSE并将最后一个错误设置为ERROR_BROKEN_PIPE:
如果正在使用匿名管道并且写入句柄已关闭,则当 ReadFile 尝试使用管道相应的读取句柄进行读取时,该函数将返回 FALSE,并且 GetLastError 将返回 ERROR_BROKEN_PIPE。
这是我的代码,我已经删除了不相关的部分:(注意:我已经更新了以allium_start遵循建议的更改,我保留原始代码以供参考,请使用较新的功能代码来查找缺陷)
bool allium_start(struct TorInstance *instance, char *config, allium_pipe *output_pipes) {
// Prepare startup info with appropriate information
SecureZeroMemory(&instance->startup_info, sizeof instance->startup_info);
instance->startup_info.dwFlags = STARTF_USESTDHANDLES;
SECURITY_ATTRIBUTES pipe_secu_attribs = {sizeof(SECURITY_ATTRIBUTES), NULL, true};
HANDLE pipes[2];
if (output_pipes == NULL) {
CreatePipe(&pipes[0], &pipes[1], &pipe_secu_attribs, 0);
output_pipes = pipes;
}
instance->startup_info.hStdOutput = output_pipes[1];
instance->startup_info.hStdError = output_pipes[1];
instance->stdout_pipe = output_pipes[0]; // Stored for internal reference
// Create the …Run Code Online (Sandbox Code Playgroud) 我正在尝试从C#中当前用户的appdata文件夹中的文件中读取,但我还在学习,所以我有这个:
int counter = 0;
string line;
// Read the file and display it line by line.
System.IO.StreamReader file = new System.IO.StreamReader("c:\\test.txt");
while ((line = file.ReadLine()) != null)
{
Console.WriteLine(line);
counter++;
}
file.Close();
// Suspend the screen.
Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)
但我不知道输入什么以确保它始终是当前用户的文件夹.
我将我的网站托管在共享主机上,最近将服务器更改为安全模式(甚至没有通知).我使用一个从服务器下载文件的功能,使用readfile()函数(我使用php).现在,在safe_mode中,此函数不再可用.是否有替代或解决方法来处理用户可以下载文件的情况?
谢谢
这个问题与此有关.由于这是一个具体的问题,我在这里单独提出了这个问题.我已经尝试创建一个文本文件"foo.txt",将其读入我的Activity中:
File file = new File("/assets/foo.txt");
if ( file.exists() ){
txtView.setText("Exists");
}
else{
txtView.setText("Does not exist");
}
Run Code Online (Sandbox Code Playgroud)
"foo.txt"文件位于我的资源文件夹中,我已经验证它存在于操作系统中.我的TextView始终从上面的代码中获取文本"不存在".我试过去了
File file = new File("/assets/foo.txt");
Scanner in = new Scanner(file);
Run Code Online (Sandbox Code Playgroud)
同样,但这会产生以下内联错误:"未处理的异常类型FileNotFoundException".Eclipse然后建议涉及try/catch,这会删除错误,但它也不能正常工作.
我也尝试将我的资源文件夹设置为"用作源文件夹",但这没有任何区别.我也尝试使用原始文件夹,因为有几个人建议没用.我没有选择,真的需要帮助.应该很容易......
另一种尝试是去
AssetManager assetManager = getResources().getAssets();
InputStream is = assetManager.open("assets/foo.txt");
Run Code Online (Sandbox Code Playgroud)
但是这会在第二行产生内联错误:"未处理的异常类型IOException".
我想强迫用户下载YouTube视频.例如这个网址.我下载视频,我可以播放原始视频,但即使是视频的长度/大小也是相同的,我在强制下载时无法播放.
function force_download($file,$video_url)
{
$video_data = file_get_contents($video_url);
file_put_contents($file, $video_data);
if(isset($file) && file_exists($file))
{
header('Content-length: ' . filesize($file));
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename= "' . $file . '"');
readfile($file);
}
}
force_download('youtube.mp4',$video_url);
Run Code Online (Sandbox Code Playgroud) 我在我的服务器上设置了一个带PHP的下载脚本,它在让用户通过Apache(X-Sendfile)下载文件之前检查一些细节.文件位于Document-Root之外.
使用Apache和Module X-Sendfile下载的代码是:
header("X-Sendfile: $fullpath");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$link_file\"");
Run Code Online (Sandbox Code Playgroud)
使用Apache和X-Sendfile时,我的客户端下载速度为500 kB/s.我还用Apache测试了它,没有X-Sendfile和Document Root中的相同文件 - 这里也是一样!
所以我测试下载相同的文件,使用相同的客户端,两侧相同的基础设施和几秒钟后通过PHP与readfile连接相同的互联网连接:
header("Pragma: no-cache");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/octet-stream");
header("Content-Length: ".(string)(filesize($fullpath)));
header("Content-Disposition: attachment; filename=\"$link_file\"");
readfile($fullpath);
Run Code Online (Sandbox Code Playgroud)
这次下载速度为9.500 kB/s!
我使用两个选项多次重复此测试,每次尝试时结果都相同.除了下载速度之外,唯一的区别是在尝试使用PHP readfile方法时,几秒钟的等待时间(取决于下载的文件的大小).当立即重复PHP readfile方法时,等待时间没有再出现.很可能是因为它在第一次存储在内存中.
我在服务器上使用专业的HP Raid系统,其平均本地速度为800 MB/s,因此不能使用Diskspeed.我也没有在Apache的httpd.conf中找到任何压缩或带宽设置.
你们中的任何人都可以解释为什么下载速度和如何改变它有如此大的差异?
先感谢您.
- 服务器:Windows Server 2008 R2 Apache/2.2.21(Win32)PHP/5.4.20
- 客户端:Windows 7旗舰版x64谷歌浏览器30.0.1599.101局域网> 100 Mbit/s
我遇到了MSBuild中的以下问题.我有一个包含列表(逐行)的文本文件(buildsolutions1.txt),其中包含我需要构建的所有解决方案以及用逗号分隔的相关开发人员电子邮件:
Common\Common.sln,am @ email,com
ExcGw/ExcDataService.sln,pm @ email.com; am @ email,com; jk@email.com; mk@email.com; Ppp@email.com
MessB/MessB/Message.sln,am @ email,com RiskS/RiskS2.sln,jp @ email.com; mz@email.com; mk@email.com; jk@email.com; ps@email.com
我需要逐行阅读这个文件,编译每个解决方案,万一它失败 - 发送电子邮件给相关的开发人员
我的想法是创建一个项目组行,其中每个项目都是这个文件中的一行,它有2个元数据值:解决方案 - 直到逗号的行的第一部分电子邮件 - 从逗号到行尾的行的第二部分
所以我创建了一个Property Grroup和一个目标ReadSolutions,如下所示.
我逐行读取文件,但我不知道如何设置每个行项目的元数据:
FirstPartOfTheCurrentLine(%(LinesFromFile.Identity))
SecondPartOfTheCurrentLine(%(LinesFromFile.Identity))
此语法不起作用:
%(LinesFromFile.Identity.Split(',')[0])
%(LinesFromFile.Identity.Split(',')[1])
也许有人会知道如何正确设置元数据,或者可能有另一种方法来完成这项任务.谢谢
这是代码:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
ToolsVersion="4.0" DefaultTargets="CoreBuild">
<PropertyGroup>
<TPath>$(MSBuildProjectDirectory)\..\tools\MSBuild Extension Pack Binaries\MSBuild.ExtensionPack.tasks</TPath>
</PropertyGroup>
<Import Project="$(TPath)"/>
<PropertyGroup>
<!-- Default working folder -->
<RootFolder Condition=" '$(RootFolder)' == '' " >c:\ff\</RootFolder>
<BuildSolutionsFile >buildsolutions1.txt</BuildSolutionsFile>
<BuildSolutionsFileFullPath >$(RootFolder)$(BuildSolutionsFile)</BuildSolutionsFileFullPath>
</PropertyGroup>
<Target Name="ReadSolutions">
<Message Text=" Build solutions text file is …Run Code Online (Sandbox Code Playgroud) 有些事情我不明白:
说in是一个文件包含:
1
2
3
Run Code Online (Sandbox Code Playgroud)
并且foo.pl:
use strict;
<>;
print;
<>;
print;
<>;
print;
Run Code Online (Sandbox Code Playgroud)
然后运行:
perl foo.pl < in
Run Code Online (Sandbox Code Playgroud)
为什么这个程序不输出任何东西?
......这一个:
use strinct;
while(<>) {
print;
}
Run Code Online (Sandbox Code Playgroud)
输出整个文件
这是我想要阅读的数据:
"Adam C. Emality","1Z620Y1V034826","14.40"
"Ethel Baeron","1Z620Y1V034604","15.19"
"Donna Lidt","1Z620Y1V034650","12.37"
Run Code Online (Sandbox Code Playgroud)
然后在读完数据之后,我想在两个集合上执行一个Join,一个是数组,一个是列表 - 我的代码如下.但是在执行读取文件行之后,我的字符串就像这样存储"\"Adam C. Emality\"" "\"1Z620Y1V034826\"" "\"14.40\""......等等.为什么会发生这种情况?我不想包括",我不知道它为什么要加入\.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FileHelpers;
using Parser;
namespace Amazon_File
{
class SpreadSheet
{
public void create(IEnumerable<SpreadList> list)
{
var steamengine = new FileHelperEngine<Records>();
var records = steamengine.ReadFile(@"C:\Users\Danny\Documents\Visual Studio 2013\Projects\Amazon File\Amazon File\Daniel.csv");
var spreadlist = from x in list
join y in records on x.Name equals y.Name
select new { y.Name, y.Track, y.worldPrice, …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试从网站上读取txt文件.
到目前为止我的脚本是:
webFile = urllib.urlopen(currURL)
Run Code Online (Sandbox Code Playgroud)
这样,我可以使用该文件.但是,当我尝试存储文件(in webFile)时,我只获得了一个指向套接字的链接.我尝试的另一个解决方案是使用read()
webFile = urllib.urlopen(currURL).read()
Run Code Online (Sandbox Code Playgroud)
然而,这似乎删除格式化(\n,\t等等)都被删除.
如果我打开这样的文件:
webFile = urllib.urlopen(currURL)
Run Code Online (Sandbox Code Playgroud)
我可以逐行阅读:
for line in webFile:
print line
Run Code Online (Sandbox Code Playgroud)
这将导致:
"this"
"is"
"a"
"textfile"
Run Code Online (Sandbox Code Playgroud)
但我得到:
't'
'h'
'i'
...
Run Code Online (Sandbox Code Playgroud)
我希望在我的计算机上获取该文件,但同时保持格式.