简体   繁体   English

Delphi:如何在 cmd 命令中将变量作为参数提供

[英]Delphi: How to give variables as parameter in a cmd command

Instead of passing a number as parameter.而不是传递一个数字作为参数。 I want to pass a variable for the IP-address.我想为 IP 地址传递一个变量。 How can I do this?我怎样才能做到这一点? I've already tried the + operator but it didnt worked.我已经尝试过 + 运算符,但没有用。

ShellExecute(
    Application.handle, 
    'open', 
    'cmd.exe', 
    PChar('/c "mysqldump -h 192.168.100.1 -uroot database table > C:/Users/user1/Desktop/export.sql"'), 
    nil, 
    SW_show
);

If I've correctly understood your question, you are looking for something to compose the command string using variables.如果我正确理解了您的问题,那么您正在寻找使用变量来组成命令字符串的内容。 You can do that in several ways, this is one (Using the Format function):您可以通过多种方式做到这一点,这是一种(使用Format功能):

var
  IPAddress : string;
begin
  IPAddress := '192.168.100.1';

  ShellExecute(
    Application.Handle,
    'open',
    'cmd.exe',
    PChar(Format('/c "mysqldump -h %s -uroot database table > C:/Users/user1/Desktop/export.sql"', [IPAddress])),
    nil,
    SW_SHOW
  );
end;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM