小编Jam*_*sPD的帖子

C#:将外部控制台程序作为隐藏运行

任何人都可以告诉我如何从Winforms应用程序生成另一个控制台应用程序,但(A)没有在屏幕上显示控制台窗口,(B)仍然获得应用程序的标准输出?目前我有以下内容:

  Process SomeProgram = new Process();
  SomeProgram.StartInfo.FileName = @"c:\foo.exe";
  SomeProgram.StartInfo.Arguments = "bar";
  SomeProgram.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  SomeProgram.StartInfo.UseShellExecute = false;
  SomeProgram.StartInfo.RedirectStandardOutput = true;
  SomeProgram.Start();
  SomeProgram.WaitForExit();
  string SomeProgramOutput = SomeProgram.StandardOutput.ReadToEnd();
Run Code Online (Sandbox Code Playgroud)

如果我将RedirectStandardOutput设置为false,则控制台应用程序将按预期隐藏,但我无法获得标准输出文本.但是,只要我将RedirectStandardOutput设置为true,窗口就会停止隐藏,尽管我能够获得程序的输出.

所以,我知道如何让控制台应用程序运行隐藏,我知道如何获得程序的输出,但我如何让它同时执行?

很多TIA

c# console process

14
推荐指数
1
解决办法
6677
查看次数

将字节数组复制到C#中的类/结构中的各个字段

在下面的示例C#代码中,我有一个从套接字读取的字节数组.我想将数据解析为'exampleClass'的各个字段(前8个字节到64位变量'field1',接下来4个字节到32位变量'field2'等)

using System;
namespace CsByteCopy
{
  class Program
  {
    class ExampleClass
    {
      public UInt64 field1;
      public UInt32 field2;
      public UInt16 field3;
      public byte[] field4 = new byte[18];
    }

    static void Main(string[] args)
    {
      byte[] exampleData =
      {
        // These 8 bytes should go in 'field1'
        0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
        // These 4 bytes should go in 'field2'
        0x08,0x09,0x0A,0x0B,
        // These 2 bytes should go in 'field3'
        0x0C,0x0D,
        // These 18 * 1 bytes should go in 'field4'
        0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
      };

      ExampleClass exampleClass = new …
Run Code Online (Sandbox Code Playgroud)

c# byte bytearray memcpy

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

c# ×2

byte ×1

bytearray ×1

console ×1

memcpy ×1

process ×1