[英]Run Bat File with C having path variable
I need to run a bat file using the userpath variable 我需要使用userpath变量运行bat文件
system("\"%HOMEPATH%\\AppData\\Roaming\\project\\Local Store\\update.bat\"");
this one doens't work, but the next one does : 这一个不起作用,但是下一个可以:
system("\"C:\\Users\\User\\AppData\\Roaming\\project\\Local Store\\update.bat\"");
But I need the first one, to make it work to every user ... Thank you in advance ! 但是我需要第一个,以便使它适用于每个用户...预先谢谢!
(Answer edited) (答案已编辑)
I think that %HOMEPATH%
expands to a directory name with one or more spaces in it. 我认为
%HOMEPATH%
扩展为目录名称,其中包含一个或多个空格。 This would explain why it worked for you once you added quotes. 这将解释为什么添加引号后它对您有用。
Originally I thought that you needed to expand the variable yourself before calling system()
but that was a mistake. 最初,我认为您需要在调用
system()
之前自己扩展变量,但这是一个错误。 The system()
command is supposed to handle a string as if you had typed it at the command line, and that includes expanding variables. 应该使用
system()
命令来处理字符串,就像您在命令行中键入它一样,并且该字符串包括扩展变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.