代码之家  ›  专栏  ›  技术社区  ›  Brett Rigby

从nant更改命令(cmd)窗口的标题

  •  2
  • Brett Rigby  · 技术社区  · 15 年前

    我希望能够在整个nant脚本的不同点上更改命令窗口的标题。

    我试图使用该任务调用“title mytargetname”,但它给出了以下错误:

    “标题”无法启动。

    The system cannot find the file specified
    

    有什么办法可以做到吗?事先谢谢!

    5 回复  |  直到 14 年前
        1
  •  2
  •   Lachlan Roche    14 年前

    您可以在自定义任务中设置控制台标题。如果任务是在 script ,生成文件是自包含的。

    一旦nant完成,控制台标题将恢复。

    <project default="title">
    
        <target name="title">
            <consoletask title='step 1'/>
            <sleep minutes="1" />
            <consoletask title='step 2'/>
            <sleep minutes="1" />
            <consoletask title='step 3'/>
            <sleep minutes="1" />
        </target>
    
        <script language="C#">
            <code>
                [TaskName("consoletask")]
                public class TestTask : Task
                {
                    private string title;
    
                    [TaskAttribute("title", Required=true)]
                    public string Title
                    {
                        get { return title; }
                        set { title = value; }
                    }
    
                    protected override void ExecuteTask() {
                        System.Console.Title = title;
                    }
                }
            </code>
        </script>
    </project>
    
        2
  •  1
  •   Drew Noakes    15 年前

    如果您将这个小程序编译为控制台应用程序:

    namespace SetTitle
    {
        internal static class Program
        {
            private static void Main(string[] args)
            {
                System.Console.Title = string.Join(" ", args);
            }
        }
    }
    

    这样就可以了:

    <exec>SetTitle.exe "Step One"</exec>
    
    <!-- Do some stuff -->
    
    <exec>SetTitle.exe "Step Two"</exec>
    

    您可以对自定义的nant任务执行相同的操作,但是所涉及的工作将更加复杂,并且您仍然需要在脚本执行期间发现nant任务程序集。

        3
  •  1
  •   t0mm13b    14 年前

    试试这个:

    ' In your command prompt
    title foobar
    
    ' The title now should say 'foobar' without quotes
    
    ' Now issue this...
    cmd /k fubar
    
    ' The title now should say 'fubar' without quotes
    

    所以我想你需要把它改成这样:

    <exec>cmd /k title one </exec>
    

    编辑: 在脚本末尾,调用 exit 命令退出 cmd.exe 命令行处理器…假设“cmd/k”有三个“exec”,则需要三个“exit”命令才能返回到原始的cmd.exe shell,将其视为在nant脚本期间从堆栈中弹出cmd.exe…

    编辑第2页: 根据布雷特的评论…只是一个想法-为什么不这样做…

    <exec>cmd /k title one </exec>
    <exec>exit</exec>
    

    设置窗口标题后立即添加“exit”命令…?

    希望这有帮助, 最好的问候, 汤姆。

        4
  •  0
  •   zoidbeck    15 年前

    可以使用cmd或批处理文件运行包含以下内容的nant脚本:

    title %1 
    %NANT_PATH%\nant.exe %1
    
        5
  •  0
  •   Drew Noakes    15 年前

    这应该有效:

    <exec>title Step One</exec>
    
    <!-- Do some stuff -->
    
    <exec>title Step Two</exec>
    

    这个用的是普通的 cmd.exe 命令。