在批处理文件中使用c#输出 [英] use c# output in batch file

查看:70
本文介绍了在批处理文件中使用c#输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在批处理文件变量中输入c#输出,有人可以帮忙。







以下是我的样本批处理文件代码。

@echo off

for / Fdelims =%% a in(C:\ Users \ u316383 \ Documents \ Backup\ConsoleApplication3.exe)设置datayyyymmdd = %% a。 ECHO datayyyymmdd。 @wait 15







简单c#代码:

使用System;

使用System.Collections.Generic;

使用System.Linq;

使用System.Text;

命名空间ConsoleApplication3

{

class Program {static void Main(string [] args)

{

Console.WriteLine(Hello World!);

}

}

}

I want to take c# output in batch file variable ,can anyone please help.



Following is my sample batch file code.
@echo off
for /F "delims=" %%a in (C:\Users\u316383\Documents\Backup\ConsoleApplication3.exe) do set datayyyymmdd=%%a. ECHO datayyyymmdd. @wait 15



simple c# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program{ static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}

推荐答案

了解FOR命令的所有变体将是一项相当大的成就,我希望您首先阅读文档 http://technet.microsoft.com/en-us/library/bb490909.aspx [ ^ ]。



将文件名视为命令并解析它的标准输出,你需要在解析关键字中添加usebackq选项并返回引用文件名。



Understanding all the variants of the FOR command would be quite an achievement and I hope you started by reading the documentation http://technet.microsoft.com/en-us/library/bb490909.aspx[^].

To have the filename treated as a command and have it's standard output parsed, you will need to add the usebackq option to your parsing keywords and back quote the filename.

for /F "usebackq delims=" %%a in (`C:\Users\u316383\Documents\Backup\ConsoleApplication3.exe`) do set datayyyymmdd=%%a. 





如果文件名包含空格,则使用后引号和双引号。



If the filename contains spaces then use back quotes and double quotes.

for /F "usebackq delims=" %%a in (`"C:\Users\u316383\Documents\Backup Files\ConsoleApplication3.exe"`) do set datayyyymmdd=%%a. 





Alan。



Alan.


这篇关于在批处理文件中使用c#输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆