Running two cmd commands in one go? - autohotkey

cd "C:\Program Files\GPSoftware\Directory Opus\"
followed by
dopusrt.exe /info documents\filelist1.txt,listsel,0
Attempting to run it like so;
2::
Run, %comspec% /k cd "C:\Program Files\GPSoftware\Directory Opus\" && %ComSpec% /k dopusrt.exe /info documents\filelist1.txt,listsel,0,, Hide
Return
Gives me an error. ==> The following variable name contains an illegal character: ", Hide"
It thinks, the commas in the second CMD command are AHK parameters.
I've tried quoting the second command in its entirety but the CMD window seem to only receive the first command.
Thank you.

The commas indeed are one problem, another problem is your usage of %comspec% /k.
Right now, what you're trying to, is use the Run(docs) command, where the parameters would be as follows:
Target = C:\WINDOWS\system32\cmd.exe /k cd "C:\Program Files\GPSoftware\Directory Opus\" && C:\WINDOWS\system32\cmd.exe /k dopusrt.exe /info documents\filelist1.txt
WorkingDir = listsel
Options = 0
OutputVarPID = , Hide
The comspec(docs) variable contains the path to cmd.exe and the /k switch(docs) means to run the specified command.
So, you of course don't want to specify these things twice. Just one at the start of the command. (Run a program (cmd.exe) with the specified parameters (/k, cd, "C:\Program Files\...))
And about the commas, in legacy syntax (you're writing legacy syntax here) you'll need to escape(docs) them with `,.
So in legacy syntax your finished command would look like this:
Run, %ComSpec% /k cd "C:\Program Files\GPSoftware\Directory Opus\" && dopusrt.exe /info documents\filelist1.txt`,listsel`,0, , Hide
And in modern expression syntax it'd look like this:
Run, % A_ComSpec " /k cd ""C:\Program Files\GPSoftware\Directory Opus\"" && dopusrt.exe /info documents\filelist1.txt,listsel,0", , Hide
I'd recommend ditching the legacy syntax and starting to just write expression syntax.
Here's a documentation page to get you started about the differenced between legacy syntax and expression syntax, if you're interested.
But really, this whole approach with cding to the directory where dopusrt.exe is seems really silly to me. Not seeing the point of it.
Should be fine to just run the dopusrt.exe program directly?
Run, % """C:\Program Files\GPSoftware\Directory Opus\dopusrt.exe"" /info documents\filelist1.txt,listsel,0", , Hide

Related

Notepad++ multiple run commands

How can I run cd "$(CURRENT_DIRECTORY)" followed by path/to/python.exe -i "$(FILE_NAME)" in the notepad++ run dialogue (F5) please?
I don't want to use nppexec because I want the program to run in the windows cmd window not the npp console. Also I specifically need to cd into the folder rather than relying on the default behaviour. I've tried separating the commands with semi-colons and commas, but no joy.
In the DOS/Windows command shell, you separate multiple commands on a single line using the ampersand character (&):
cmd /c cd \ptools & dir /s /b *.awk & pause
This changes to the \ptools directory, then shows every AWK file and waits for a key to be pressed.
In your case:
cmd /c cd "$(CURRENT_DIRECTORY)" & path\to\python.exe -i "$(FILE_NAME)"

How to execute multiple commands through perl script

I am trying to use perl to run two different commands - both of which need to be executed in a separate command prompt.
Here are some of the details:
when I run
system('start cmd /k "cd c:\PerlExamples && perl Perl_Ex_1.pl"');
it works as expected - it opens a new command prompt, paths to the directory I need and runs my script.
However, I want to use this system... command in a loop where each time I am running a different example script.
But when I run the following lines of code,
my $cmd = "perl Perl_Ex_1.pl";
system("start cmd /k cd c:\PerlExamples && $cmd");
it opens a new command prompt and paths to the directory I need. But it runs my example script in the original window and not in the newly opened command prompt.
Is there a way for me to do this?
Thank you.
Thanks to the wisdom of the perl monks, I found the solution to my problem.
Link to the solution:
http://www.perlmonks.org/?node_id=1173278
The solution is to either use:
my $cmd = "perl Perl_Ex_1.pl";
system(qq{start cmd /k "cd c:\\PerlExamples && $cmd"});
or use:
my $cmd = "perl Perl_Ex_1.pl";
system qq[ start /D c:\\PerlExamples cmd /k $cmd ];
Thank you.

check_nrpe put $ at end of check string

i've a problem with my powershell nagios script, mounted on a MS Windows Server 2008 64bit, with a NRPE_NT daemon.
I've declared the command like this:
command[check_files]=cmd /c echo C:\nrpe\libexec\check_file.ps1 $ARG1$; exit($lastexitcode) | powershell.exe -command -
I've set ExecutionPolicy as unrestricted
I've restart NRPE_NT Services and declared command on console, like this:
$USER1$/check_nrpe -H $HOSTADDRESS$ -t 60 -c check_files -a $ARG1$
Now, why if i run it locally, it works good:
C:\>cmd /c echo C:\nrpe\libexec\_file.ps1 C:\nrpe; exit($lastexitcode)| powershell.exe -command -
No file/s present with this string
But if i run it by check_nrpe i receive this output:
'-' was specified with the -Command parameter: no other arguments to -Command are permitted.
In Debug mode, on NRPE.log i can see this:
Running command: cmd /c echo C:\nrpe\libexec\check_file.ps1 C:\nrpe;
exit($lastexitcode) | powershell.exe -command - $
Command completed with return code 0
Why in this way, check_nrpe add a dollar character ($) at end string, derailing the entire control ?
Thanks in advance
I'm not sure if this will help your situation, but I just figured out something in my environment that was causing something similar. Here was my NRPE command comfiguration:
command[foo]=grep file '^pattern$'
Everything was fine until I wanted to add another parameter after the '^pattern$' parameter... that new parameter (at the end of the command-line) would get an extra $ appended to the end.
It seems that NRPE requires $ to be escaped, otherwise it thinks that it's a variable reference and does odd things with it. I was expecting that the quoting would make it so that no escaping was required, but NRPE's configuration files don't follow shell-style quoting rules. So, changing my NRPE configuration to this solved my problem:
command[foo]=grep file '^pattern$$'
Note the double $$ in the revised NRPE command definition.

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.

How to create a file without a Command Prompt window

I'm using WinRAR SFX module to create an installation, and use its presetup option to run some preliminary tests.
Since wscript can only accept vbs file, and not the script itself, I first run "cmd /c echo {...script code...} > setup.vbs", and then I run "wscript setup.vbs". The run of the first cmd command opens a brief command window, and I would really like to avoid this. I thought of using RunDll32 to write this data, but couldn't find any suitable API to use.
Can anyone think of a way to bypass it and create a small file with a small VBScript text without opening a Command Prompt window?
Thanks a lot,
splintor
Is the script code already in a file? If so,
You can use the TYPE command to send the script to a file:
TYPE [script_file] > setup.vbs
or COPY the script file:
COPY [script_file] setup.vbs
If the script code is in the body of your cmd, you can use the START command to run the cmd without a window (/b flag):
START /B cmd /c echo {...script code...} > setup.vbs
Rather than use cmd /c echo {...script code...} > setup.vbs as a presetup step, perhaps you could package a VBscript with your install that does your preliminary tests and creates setup.vbs, and then calls setup.vbs for you. You'd have to put this in the setup portion of the WinRAR script.
You can call another VBScript from VBScript like this:
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.Run "wscript d:\setup.vbs, ,True
See this MSDN link for the syntax of the Run command.