In my Visual Studio Pre-built command line I have a newly created line
Powershell.exe -file "$(SolutionDir)Folder1\MyPowerShell.ps1"
And in this PowerShell script, it runs an .exe with some parameters
.\MyProgram.exe .\SomeFileArg.xml
When I run just the PowerShell script locally, either as ./MyPowerShell.ps1 or copy pasting the command into my PowerShell, it works.
But when I build my Visual Studio, this doesn't occur. I get the error .\MyProgram.exe.exe : The term '.\MyProgram.exe' is not recognized as the name of a cmdlet, 2> function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the 2> path is correct and try again. If I include the absolute path instead in my PowerShell script, then it works.
How can I achieve this with local paths? Or is there a variable so I don't have to hardcode the absolute path?
You can declare the local path (where the script file resides) as a variable in your code using:
$PSScriptRoot
https://riptutorial.com/powershell/example/27231/-psscriptroot
Related
When I am trying to run PSEXEC it works perfectly when typed manually at powershell
but when run the command through Visual Studio's terminal it display the following error
psexec : The term 'psexec' is not recognized as the name of a cmdlet, function, script file, or operable program.
Note that
When parsing this cmd in automation code in VS, the remote exe file will not be opened
I already added the path to my system variables but still when I type swipl in the command prompt it doesn't open the program.
System Variables
When you add the path of SWIPL which is mostly found at "C:\Program Files\swipl\bin" (unless specified explicitly) to your System Variable - PATH. Then reopen you command prompt and try again.
I have a ./configure file that I'm supposed to run by putting it in the command prompt. It works when I run it in the git prompt but when I run it in the Windows command prompt it gives me:
C:\cygwin\home\doxygen\configure> configure
'configure' is not recognized as an internal or external command,
operable program or batch file.
Even though I'm in the correct directory (and running dir shows me that the file is there) it still stays that it cannot find the file. This is the same for all files that don't have an extension on them. Why does this happen and how can I get this to work?
./configure is not a program. It's more of a shell script usually. My analogy may not be good but consider it to be the equivalent of windows batch files (in this case you can say it's a .sh without the extension).
It will only run from a cygwin/unix shell.
I am trying to make a simple script to set my gcc variables. as a .bat file.
the variable is set like this
$env:Path += ";C:\Users\Brett\Compilers\MinGW\bin"
this runs just fine when I type/paste it into power shell.
but when I paste into a script myscript.bat, and run it through powershell I get this error:
C:\Users\Brett\Compilers>"$env:Path += ";C:\Users\Brett\Compilers\MinGW\bin""
The filename, directory name, or volume label syntax is incorrect.
PS C:\Users\Scruffy\Compilers>
PowerShell is a seperate execution enviroment from with Windows Command Line (cmd.exe)
If you want to run powershell commands from a batch file you need to save the powershell script (.ps1) and pass it into powershell.exe as a command line argument.
Example:
powershell.exe -noexit c:\scripts\test.ps1
More Information is available here on Microsoft TechNet
In general, leave batch stuff to .BAT files and put PowerShell stuff into .ps1 files.
I can duplicate your results here - but those are to be expected. Cmd.exe sees a string then a path and then gets quite confused as the syntax is not one that the command prompt can handle. So it gives that error message.
If you want to add stuff to your path, then why not put the statement inside a .ps1 script file?
As mentioned by others, you need to save the code in a .ps1 file and not .bat.
This line (from Setting Windows PowerShell path variable) will do the trick:
$env:Path = $env:Path + ";C:\Users\Brett\Compilers\MinGW\bin"
Or even shorter:
$env:Path += ";C:\Users\Brett\Compilers\MinGW\bin"
When cvs is typed in cmd.exe in windows 7 nothing is output. The path of the cvs is already in the PATH :C:\Program Files (x86)\CVSNT\; When typing "C:\Program Files (x86)\CVSNT\cvs" there are outputs there. But when other .exe e.g. calc is typed the corresponding program can be executed. Any idea?
This might sound like a strange suggestion, but try cvs.exe instead of just cvs. Without specifying an extension, your operating system will search for the first file that matches the name, cvs. If it happens to find cvs.bat in one of your paths, then it will execute the .bat file instead of the.exe.
If you have cvs.bat , cvs.com, and cvs.exe within the same directory. The order of precedence would be the following:
cvs.com
cvs.bat
cvs.exe
I have a strong suspicion that there's a blank cvs.bat file hidden somewhere in one of folders defined in your path variable, and that you are actually running this batch file when you type cvs.
HI the answer is Run the exe with full path like "C:\Program Files (x86)\CVSNT\cvs.exe" followed by CVS arguments like -q Checkout.....