Как реализовать stdin, stdout обертка?

Вы хотите использовать Приложение. Конфигурация.

, Когда Вы добавляете новый объект к проекту, существует что-то названное Конфигурационным файлом Приложений. Добавьте это.

Тогда Вы добавляете ключи в разделе configuration/appsettings

Как:

<configuration>
 <appSettings>
  <add key="MyKey" value="false"/>

Получают доступ к участникам путем выполнения

System.Configuration.ConfigurationSettings.AppSettings["MyKey"];

, Это работает в .net 2 и выше.

5
задан Łukasz Lew 13 December 2009 в 02:26
поделиться

4 ответа

Expect создан для автоматизации запуска других программ - по сути, вы пишете что-то вроде обычного текста:

Запустите эту программу. Когда он напечатает слово «имя пользователя», отправьте ему мое имя пользователя. Когда он отправит «пароль», отправьте ему мой пароль.

Это действительно здорово для работы с другими программами.

3
ответ дан 15 December 2019 в 01:03
поделиться

Вы можете перезаписать stdin и stdout модуля sys

import sys
sys.stdin, sys.stdout = wrapper.stdin, wrapper.stdout

Это должны быть файловые объекты, открытые для чтения и записи соответственно. Исходные stdin и stdout находятся по адресу

sys.stdin, sys.stdout = sys.__stdin__, sys.__stdout__
0
ответ дан 15 December 2019 в 01:03
поделиться

Предполагая, что X и Y - файлы, и что вы можете вызывать программу более одного раза:

#!/bin/bash

test "`program <X`" = "`cat Y`" && program

Или, чтобы сбой более подробно:

#!/bin/bash

if [[ `program <X` != `cat Y` ]]; then
    echo -e "Assertion that input X produces Y failed, exiting."
    exit 1
fi

program

Если вы вызываете программу только один раз, ожидайте - гораздо более простая альтернатива, чем переназначение стандартного файлового ввода-вывода на лету.

1
ответ дан 15 December 2019 в 01:03
поделиться

I'm a little confused as to what exactly you're trying to achieve; as I understand you wish to:

  1. Start the wrapper program specifying the input X, and expected output Y.
  2. Have the wrapper initiate the target program attaching input X to it's stdin, and verifying that it's output matches Y.
  3. Have the target program return, and after output is verified, rerun it from the same instance of the wrapper program, this time using the wrapper programs stdin and stdout.

If this is the case you want to do this:

  1. Have the wrapper program open pipes for the stdin and stdout of the target program.
  2. Fork, and close the appropriate ends of said pipes.
  3. Have the parent process and verify the output, while the child exec()s and executes thh target program.
  4. Wait for the child process to terminate when it's stdout closes.
  5. Have the wrapper program exec() into the target program.
  6. Now the target program will be executing as normal.

If this is correct, I can provide a ~30 line C program, or ~10 line Python program that achives this.

0
ответ дан 15 December 2019 в 01:03
поделиться
Другие вопросы по тегам:

Похожие вопросы: