I need to run a bat file using the userpath variable
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. 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. The system()
command is supposed to handle a string as if you had typed it at the command line, and that includes expanding variables.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.