Each one of the following commands when entered manually in the normal windows command prompt (cmd, not powershell) runs fine one after the other:
cd cmake\windows\rel
"C:\Program Files (x86)\Intel\oneAPI\setvars.bat"
vtune -collect hotspots --app-working-dir=%cd% -- %cd%/CMakeProject
set /p name="Enter Hotspot Folder name: "
vtune-gui %name%/%name%.vtune
Essentially, from within my project folder, I navigate to the folder where the executable is built (first line), folder cmake\windows\rel
, then I load the environment variables by running the batch file setvars.bat
. This is then followed by running the profiler via the vtune
command. Then, after accepting a user input of the folder name, that folder name is provided as an input to the vtune-gui
command.
Note that vtune
and vtune-gui
are not in the Windows path. setvars.bat
temporarily for the cmd session creates this path and allows me to use vtune
and vtune-gui
on the command line.
When I try these commands via a batch file (bfile.bat
) from within the default powershell terminal of VSCode, I have the following:
PS MyProjectFolder> .\bfile.bat
MyProjectFolder> cd cmake\windows\rel
MyProjectFolder\cmake\windows\rel> "C:\Program Files (x86)\Intel\oneAPI\setvars.bat"
...output of setvars.bat here...it runs without errors...
PS MyProjectFolder>
The third, fourth and fifth lines of the batch file do not run at all and I do not get any output from powershell indicating some error or so occurred. The last line of the output above tells me that I am back to MyProjectFolder
now. Also, note that only the first and last line of the output above are prefixed with PS
. The second, third and other lines of output do not have that prefix.
How can I get the batchfile to run and perform all of the five steps which currently I am forced to do manually?
In your batch file (bfile.bat
), replace:
"C:\Program Files (x86)\Intel\oneAPI\setvars.bat"
with:
call "C:\Program Files (x86)\Intel\oneAPI\setvars.bat"
This ensures that setvars.bat
returns control to your batch file and resumes execution; without call
, execution of your batch file ends when setvars.bat
ends.
Run cmd /c call /?
for details.
Note:
Any batch file launched from PowerShell of necessity runs in a (cmd.exe
) child process, so that any changes to the working directory and environment variables performed in a batch file are not seen by the calling PowerShell session.
Thus, if you wanted to call setvars.bat
and have PowerShell's environment variables modified, additional work would be needed; see this answer for details.