psexec not executing command once I pass in command line arguments - psexec

I have to run the following command remotely on another server, the arguments are prefixed with !=:
wdrspc.exe !=BATCHTEST1,LGTY_PLAN_01
This works (but the exe fails because I'm not passing in any arguments):
psexec \\kiklogiappsd "c:\Program Files (x86)\Logility\SPC8.0\wdrspc.exe"
This does not work (psexec says system cannot find the file specified):
psexec \\kiklogiappsd "c:\Program Files (x86)\Logility\SPC8.0\wdrspc.exe !=BATCHTEST1,LGTY_PLAN_01"
I'm stumped, is it the != syntax throwing off psexec?

The correct command line would be:
psexec \\kiklogiappsd "c:\Program Files (x86)\Logility\SPC8.0\wdrspc.exe" !=BATCHTEST1,LGTY_PLAN_01
The program arguments should not be in quotes with the program path, or they'll be interpreted as part of the program path. When you quote a space in a command line argument, that tells the shell that the space is part of the argument, rather than separating two arguments. That's why you quote anything in C:\Program Files (x86). But you want an argument-separating space between the program path and its arguments.

Related

Run output of command as powershell incantation

I have a bash script that generates a program incantation (docker run ... with a bunch of arguments) and prints it to standard output. I want to run the output from powershell, with the optional possibility to tack on other arguments afterwards.
I've tried
D:\> & $(wsl ./my-bash-script.sh) some more args
but I get the error
The term 'docker run --rm -ti [<redacted>]' is not recognized as the name of cmdlet, function, script file, or operable program. Check the spelling of the name, or ifa path was included, verify that the path is correct and try again.
Apparently, & interprets the entire output as a single command, when in fact it's only the first word of the output that is a command; the rest is arguments.
Is there a way to do what I want?
Yes, & only supports a command name or path as its first argument - you cannot include arguments.
What you need is Invoke-Expression:
Invoke-Expression "$(wsl ./my-bash-script.sh) some more args"
Note: You'd only need & inside the string if the .sh script output a command with a quoted executable path.
Also note that PowerShell will not always interpret a given command line the same way as a POSIX-like shell (such as Bash), given that it recognizes additional metacharacters at the start of arguments; notably, arguments prefixed with # or { will not be taken as literals by PowerShell.
As an aside: While this is a legitimate use case for Invoke-Expression - assuming you trust the output from your .sh script - Invoke-Expression should generally be avoided.

Can't run line command with AHK

Anyone why my parameters are not active please ?
thanks
Run, "C:\Program Files (x86)\rFactor\rFactor Dedicated.exe" "+oneclick +profile "serveur01""
Autohotkey doesn't need quotes for the program - it is not the same as batch scripting.
If your program requires quotes for the commandline parameter, then you include quotes.
But you don't have any spaces in the parameters, so you don't need any quotes at all.
Run, C:\Program Files (x86)\rFactor\rFactor Dedicated.exe +oneclick +profile serveur01

perl command prompt with arguments

Is it possible to start a command prompt from perl script using Win32::Process::Create package?
I am trying to start DOORS from perl script. The executable is present in C:\Program Files\DOORS\bin\runDOORS9.rck.
I need to start the runDOORS9.rck with the argument COL9 to change the Database.
Try the good old system() function. On Windows it would use the cmd.exe, the system shell, to execute the command.
Since what you try to launch doesn't seem to be an .exe file, potentially you would have to use the start command of the cmd.exe.
For example:
system(qq{start "" "C:\Program Files\DOORS\bin\runDOORS9.rck" COL9});
(The first "" is required due to quirky argument parsing of the Window's shell commands. See help start for more information.)

Starting a program in command prompt just opens up another command prompt window

Does anyone know why when I type the following command in my command prompt, instead of opening the intended program, it just opens up another command prompt window? It's the same if I create a batch file with the command.
start "C:\Program Files\BrokerLink AutoPrint\BrokerLinkAutoPrint.exe"
An extra pair of double quotes "" should make this work as expected:
start "" "C:\Program Files\BrokerLink AutoPrint\BrokerLinkAutoPrint.exe"
START regards the first quoted parameter as the window-title, unless it's the only parameter - and any switches up until the executable name are regarded as START switches.
Alternatively, you could just use:
call "C:\Program Files\BrokerLink AutoPrint\BrokerLinkAutoPrint.exe"

Perl running a batch file #echo command not found

I am using mr on Windows and it allows running arbitrary commands before/after any repository action. As far as I can see this is done simply by invoking perl's system function. However something seems very wrong with my setup: when making mr run the following batch file, located in d:
#echo off
copy /Y foo.bat bar.bat
I get errors on the most basic windows commands:
d:/foo.bat: line 1: #echo: command not found
d:/foo.bat: line 2: copy: command not found
To make sure mr isn't the problem, I ran perl -e 'system( "d:/foo.bat" )' but the output is the same.
Using xcopy instead of copy, it seems the xcopy command is found since the output is now
d:/foo.bat: line 1: #echo: command not found
Invalid number of parameters
However I have no idea what could be wrong with the parameters. I figured maybe the problem is the batch file hasn't full access to the standard command environment so I tried running it explicitly via perl -e 'system( "cmd /c d:\foo.bat" )' but that just starts cmd and does not run the command (I have to exit the command line to get back to the one where I was).
What is wrong here? A detailed explanation would be great. Also, how do I solve this? I prefer a solution that leaves the batch file as is.
The echo directive is executed directly by the running command-prompt instance.
But perl is launching a new process with your command. You need to run your script within a cmd instance, for those commands to work.
Your cmd /c must work. Check if you have spaces in the path you are supplying to it.
You can use a parametrized way of passing arguments,
#array = qw("/c", "path/to/xyz.bat");
system("cmd.exe", #array);
The echo directive is not an executable and hence, it errors out.
The same is true of the copy command also. It is not an executable, while xcopy.exe is.