【问题标题】:Dos create a batch file and run with multiple C++ programsDos 创建一个批处理文件并与多个 C++ 程序一起运行
【发布时间】:2010-03-15 17:27:35
【问题描述】:

尊敬的先生们,

我的名字是@nimit。我想创建一个批处理文件并在 DOS 提示符下运行它。批处理文件将执行我编写的 C++ 程序。输出应存储在单个文本文件中。我该怎么做?

C++ 程序输出应存储在特定的文本文件中。

提前致谢, @nimit

【问题讨论】:

    标签: c++ batch-file dos


    【解决方案1】:

    你可以这样做:

    programname > outputgoeshere.txt
    

    收集输出:

    programname1 >> outputgoeshere.txt
    programname2 >> outputgoeshere.txt
    programname3 >> outputgoeshere.txt
    

    【讨论】:

    • 可能是追加而不是覆盖?
    • 但我想创建批处理文件,然后它输出到 dos 中的文本文件中,假设我有 3 个 c++ 程序,输出存储在单个文本文件中
    • 追加将使用 >> 而不是单个 > (覆盖)
    • 但是如何在dos中创建批处理文件
    • @user - 将这些语句放在扩展名为 .bat 的文本文件中,您将获得批处理文件。
    【解决方案2】:

    Shell 脚本(批处理文件是其中的一种形式)是每个程序员都应该知道的事情。几年前我发现了一本非常棒的书:Stephen Kochan 和 Patrick Wood 的 Unix Shell Programming。诚然,它是 Unix —— bash 比 DOS 强大得多,但原理是一样的。 Windows 正在使用 bash 通过 powershell 提供的许多工具。

    有关列出所有 CMD 程序的出色网站,请访问 http://ss64.com/nt/。该站点还列出了类似的 bash 和 powershell 命令。我也喜欢他如何向您展示如何在批处理文件中实现伪函数、命令行参数和各种很酷的东西:http://ss64.com/nt/syntax.html

    祝你好运!

    【讨论】:

      【解决方案3】:

      以下将程序输出(stdout)重定向到文件(覆盖文件或如果文件不存在则创建)

      $ command-name > output.log
      

      以下将程序输出(stdout)重定向到文件(附加文件或如果文件不存在则创建)

      $ command-name >> output.log
      $ command-name >> output.log
      

      以下将程序错误消息重定向到名为error.log的文件:

      $ command-name 2> error.log
      

      将标准错误(stderr)和标准输出重定向到文件,使用以下语法:

      $ command-name &> output_error.log
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-18
        • 1970-01-01
        相关资源
        最近更新 更多