Tag: stdin

带有重定向输入/输出流的HTML中的wkhtmltopdf相对路径将不起作用

我正在使用wkhtmltopdf.exe(版本0.12.0 final)从html文件生成pdf文件,我使用.NET C# 我的问题是只通过在html中指定相对路径来使javascript,样式表和图像工作。 现在,如果我使用绝对路径,我可以使用它。 但它不适用于相对路径,这使得整个html生成有点复杂。 我把我做的事情煮成了下面的例子: string CMDPATH = @”C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe”; string HTML = string.Format( “{2}”, “./sohlogo.png”, “./ACLASS.jpg”, DateTime.Now.ToString()); WriteFile(HTML, “test.html”); Process p; ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = CMDPATH; psi.UseShellExecute = false; psi.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory; psi.CreateNoWindow = true; psi.RedirectStandardInput = true; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; psi.Arguments = “-q – -“; […]

在不编写文件的情况下在Python和C#之间传递数据

我想在Python和C#之间传递二进制信息。 我假设您可以打开一个标准的输入/输出通道,并像文件一样读写,但是有很多可移动的部分,而且我不太了解C#。 我想做这种事情,但不写文件。 # python code with open(DATA_PIPE_FILE_PATH, ‘wb’) as fid: fid.write(blob) subprocess.Popen(C_SHARP_EXECUTABLE_FILE_PATH) with open(DATA_PIPE_FILE_PATH, ‘rb’) as fid: ‘Do stuff with the data’ // C# code static int Main(string[] args){ byte[] binaryData = File.ReadAllBytes(DataPipeFilePath); byte[] outputData; // Create outputData File.WriteAllBytes(outputData) 我已经尝试了几种使用标准输入/输出的不同方法,但我没有运气匹配它们,就像我说的那样,有许多活动部件。 我尝试过类似的东西 p = subprocess.Popen(C_SHARP_EXECUTABLE_FILE_PATH, stdin=subprocess.PIPE, stdout=subprocess.PIPE) p.stdin.write(blob) p.stdin.close() 要么 p = subprocess.Popen(C_SHARP_EXECUTABLE_FILE_PATH, stdin=subprocess.PIPE, stdout=subprocess.PIPE) […]

将图像写入Process.StandardInput.BaseStream的更快捷方式

我试图将大量桌面捕获的图像发送到编码器(FFmpeg)stdin。 以下代码示例有效。 CaptureScreen()函数在5-10毫秒内提供图像。 如果我将图像保存在MemoryStream中,几乎没有时间。 但我只能每隔45毫秒将1张图像保存到proc.StandardInput.BaseStream。 public void Start(string bitrate, string buffer, string fps, string rtmp, string resolution, string preset) { proc.StartInfo.FileName = myPath + “\\ffmpeg.exe”; proc.StartInfo.Arguments = “-f image2pipe -i pipe:.bmp -vcodec libx264 -preset ” + preset + ” -maxrate ” + bitrate + “k -bufsize ” + buffer + “k -bt 10 -r ” […]

检查C#中的标准输入

我正在编写一个小命令行实用程序,其目的是解析另一个实用程序的输出。 我希望它可以通过两种方式调用: c:\> myutility filewithoutput.txt 要么, c:\> otherutility -args | myutility 所以,基本上,标准或文件参数。 我对此的第一次尝试看起来像这样: TextReader reader; if (args.Length > 1) { reader = new StreamReader(new FileStream(args[1], FileMode.Open)); } else { reader = Console.In; } Process(reader); 文件参数工作正常,并将实用程序的输出传递给我的实用程序工作正常,但如果您只是正常调用它(没有参数和没有管道数据),它会挂起。 或者说,它阻止等待从标准读取。 我的第二稿看起来像这样: TextReader reader; if (args.Length > 1) { reader = new StreamReader(new FileStream(args[1], FileMode.Open)); } else { if(Console.KeyAvailable) { […]

C#处理标准输入

我目前正在尝试通过命令行断开网络文件夹,并使用以下代码: System.Diagnostics.Process process2 = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.FileName = “cmd.exe”; startInfo.Arguments = “/C NET USE F: /delete”; startInfo.RedirectStandardError = true; startInfo.RedirectStandardInput = true; startInfo.RedirectStandardOutput = true; startInfo.UseShellExecute = false; startInfo.CreateNoWindow = true; process2.StartInfo = startInfo; process2.Start(); StreamWriter sw = process2.StandardInput; sw.WriteLine(“Y”); sw.Close(); process2.WaitForExit(); process2.Close(); 偶尔,我收到消息“继续断开并强行关闭它们是否可以?(是/否)[N]”,我想回复“Y”,但我似乎遇到了问题。 有谁知道为什么我的代码没有输入标准输入“Y”?

无法将命令发送到cmd.exe进程

我正在尝试使用StandardInput.WriteLine(str)将命令发送到打开的cmd.exe进程,但是似乎没有发送任何命令。 首先,我使用全局变量p( Process p )打开一个过程。 p = new Process() { StartInfo = { CreateNoWindow = true, UseShellExecute = false, RedirectStandardError = true, RedirectStandardInput = true, RedirectStandardOutput = true, FileName = @”cmd.exe”, Arguments = “/C” //blank arguments } }; p.Start(); p.WaitForExit(); 之后,我尝试使用一种简单的方法发送命令,该方法将结果记录在文本框中。 private void runcmd(string command) { p.StandardInput.WriteLine(command); var output = p.StandardOutput.ReadToEnd(); TextBox1.Text = output; } […]

我可以将二进制文件放入stdin吗? C#

与此问题相关的问题用7z加密二进制文件没有文件名? 在C#中我如何将二进制文件放入STDin? 我希望下面的内容可以正常运行,但它不会。 这是有道理的。 那么我如何推送一个byte []数组呢? new BinaryWriter(p.StandardInput.FormatProvider);