相关疑难解决方法(0)

如何从GUI应用程序向控制台应用程序发送命令

我有一个控制台应用程序,我从GUI应用程序启动.控制台应用程序获取文件名的参数以进行解析和处理.目前我能够捕获其输出并将其显示在GUI应用程序中,但我希望能够向其发送命令以便控制甚至停止其执行.

如何向控制台应用程序发送命令或字符串或任何内容,最好使用我打开的管道来读取其输出?

const
  CReadBuffer = 2400;
var
  saSecurity: TSecurityAttributes;
  hRead: THandle;
  hWrite: THandle;
  suiStartup: TStartupInfo;
  piProcess: TProcessInformation;
  pBuffer: array[0..CReadBuffer] of AnsiChar;
  dRead: DWord;
  dRunning: DWord;
  dWritten: DWord;
  Command: String;
  BytesLeft: Integer;
  BytesAvail: Integer;
begin
  saSecurity.nLength := SizeOf(TSecurityAttributes);
  saSecurity.bInheritHandle := True;
  saSecurity.lpSecurityDescriptor := nil;

  if CreatePipe(hRead, hWrite, @saSecurity, 0) then
  begin
    FillChar(suiStartup, SizeOf(TStartupInfo), #0);
    suiStartup.cb := SizeOf(TStartupInfo);
    suiStartup.hStdInput := hRead;
    suiStartup.hStdOutput := hWrite;
    suiStartup.hStdError := hWrite;
    suiStartup.dwFlags := STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;
    suiStartup.wShowWindow := SW_HIDE;
    Command := 'messageparser.exe c:\messagefile.msg';
    UniqueString(Command);
    if CreateProcess(nil, …
Run Code Online (Sandbox Code Playgroud)

delphi console

9
推荐指数
1
解决办法
6174
查看次数

如何将按键发送到正在运行的进程对象?

我试图让 C# 启动一个应用程序(在本例中是开放办公室),并开始发送该应用程序按键,这样它看起来就像有人正在打字一样。因此,理想情况下,我能够向正在运行的 Open Office 进程发送字母“d”的按键,然后 Open Office 会在纸上键入 d。谁能给我指导如何解决这个问题?我尝试执行以下操作:

p = new Process();
p.StartInfo.UseShellExecute = true;
p.StartInfo.CreateNoWindow = false;
p.StartInfo.FileName = processNames.executableName;

p.Start();

p.StandardInput.Write("hello");
Run Code Online (Sandbox Code Playgroud)

但这并没有达到我想要的效果——我没有看到在开放式办公室中输入的文本。

.net c# keyboard input process

5
推荐指数
1
解决办法
8030
查看次数

标签 统计

.net ×1

c# ×1

console ×1

delphi ×1

input ×1

keyboard ×1

process ×1