将命令输出重定向到 Haxe 中的文本文件
Redirect output of a command to a text file in Haxe
我正在尝试在 Haxe 中执行以下代码。
class File_Operations
{
public static function main()
{
Sys.command("ipconfig",[">","C:\Users\ila5\Desktop\Temp.txt"]);
}
}
但是,我得到以下错误
Error: unrecognized or incomplete command line.
USAGE:
ipconfig [/allcompartments] [/? | /all |
/renew [adapter] | /release [adapter] |
/renew6 [adapter] | /release6 [adapter] |
/flushdns | /displaydns | /registerdns |
/showclassid adapter |
/setclassid adapter [classid] |
/showclassid6 adapter |
/setclassid6 adapter [classid] ]
where
adapter Connection name
(wildcard characters * and ? allowed, see examples)
Options:
/? Display this help message
/all Display full configuration information.
/release Release the IPv4 address for the specified adapter.
/release6 Release the IPv6 address for the specified adapter.
/renew Renew the IPv4 address for the specified adapter.
/renew6 Renew the IPv6 address for the specified adapter.
/flushdns Purges the DNS Resolver cache.
/registerdns Refreshes all DHCP leases and re-registers DNS names
/displaydns Display the contents of the DNS Resolver Cache.
/showclassid Displays all the dhcp class IDs allowed for adapter.
/setclassid Modifies the dhcp class id.
/showclassid6 Displays all the IPv6 DHCP class IDs allowed for adapter.
/setclassid6 Modifies the IPv6 DHCP class id.
The default is to display only the IP address, subnet mask and
default gateway for each adapter bound to TCP/IP.
For Release and Renew, if no adapter name is specified, then the IP address
leases for all adapters bound to TCP/IP will be released or renewed.
For Setclassid and Setclassid6, if no ClassId is specified, then the ClassId is removed.
Examples:
> ipconfig ... Show information
> ipconfig /all ... Show detailed information
> ipconfig /renew ... renew all adapters
> ipconfig /renew EL* ... renew any connection that has its
name starting with EL
> ipconfig /release *Con* ... release all matching connections,
eg. "Wired Ethernet Connection 1" or
"Wired Ethernet Connection 2"
> ipconfig /allcompartments ... Show information about all
compartments
> ipconfig /allcompartments /all ... Show detailed information about all
compartments
当我在cmd中直接运行上述命令时,效果很好。
我想知道如何在 Haxe 中使用 Sys.command() 将输出重定向到文本文件。有什么想法吗?
我认为 ">" 运算符在这里将被解释为一个参数(而不是标准输出重定向),但是使用 Sys.command 你无法避免它。
您可以做的是直接在 haxe 中读取 "ipconfig" 命令的标准输出并将其保存为文件。
此示例代码应该适合您
var p = new Process("ipconfig", []);
var out:String = p.stdout.readAll().toString();
p.close();
File.saveContent("ipconfig.txt", out);
我正在尝试在 Haxe 中执行以下代码。
class File_Operations
{
public static function main()
{
Sys.command("ipconfig",[">","C:\Users\ila5\Desktop\Temp.txt"]);
}
}
但是,我得到以下错误
Error: unrecognized or incomplete command line.
USAGE:
ipconfig [/allcompartments] [/? | /all |
/renew [adapter] | /release [adapter] |
/renew6 [adapter] | /release6 [adapter] |
/flushdns | /displaydns | /registerdns |
/showclassid adapter |
/setclassid adapter [classid] |
/showclassid6 adapter |
/setclassid6 adapter [classid] ]
where
adapter Connection name
(wildcard characters * and ? allowed, see examples)
Options:
/? Display this help message
/all Display full configuration information.
/release Release the IPv4 address for the specified adapter.
/release6 Release the IPv6 address for the specified adapter.
/renew Renew the IPv4 address for the specified adapter.
/renew6 Renew the IPv6 address for the specified adapter.
/flushdns Purges the DNS Resolver cache.
/registerdns Refreshes all DHCP leases and re-registers DNS names
/displaydns Display the contents of the DNS Resolver Cache.
/showclassid Displays all the dhcp class IDs allowed for adapter.
/setclassid Modifies the dhcp class id.
/showclassid6 Displays all the IPv6 DHCP class IDs allowed for adapter.
/setclassid6 Modifies the IPv6 DHCP class id.
The default is to display only the IP address, subnet mask and
default gateway for each adapter bound to TCP/IP.
For Release and Renew, if no adapter name is specified, then the IP address
leases for all adapters bound to TCP/IP will be released or renewed.
For Setclassid and Setclassid6, if no ClassId is specified, then the ClassId is removed.
Examples:
> ipconfig ... Show information
> ipconfig /all ... Show detailed information
> ipconfig /renew ... renew all adapters
> ipconfig /renew EL* ... renew any connection that has its
name starting with EL
> ipconfig /release *Con* ... release all matching connections,
eg. "Wired Ethernet Connection 1" or
"Wired Ethernet Connection 2"
> ipconfig /allcompartments ... Show information about all
compartments
> ipconfig /allcompartments /all ... Show detailed information about all
compartments
当我在cmd中直接运行上述命令时,效果很好。
我想知道如何在 Haxe 中使用 Sys.command() 将输出重定向到文本文件。有什么想法吗?
我认为 ">" 运算符在这里将被解释为一个参数(而不是标准输出重定向),但是使用 Sys.command 你无法避免它。 您可以做的是直接在 haxe 中读取 "ipconfig" 命令的标准输出并将其保存为文件。 此示例代码应该适合您
var p = new Process("ipconfig", []);
var out:String = p.stdout.readAll().toString();
p.close();
File.saveContent("ipconfig.txt", out);