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.
Related
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
I'm trying to run a command with AutoHotKey that I would normally run with cmd.exe. Here is the command:
pandoc -s "C:\input.txt" -o "D:\output.html"
This is how I do it in AutoHotKey:
#a::
run pandoc -s "C:\input.txt" -o "D:\output.html"
return
The only problem is that this opens up the a command prompt called "pandoc". Normally I'd just type in the command in cmd.exe and it would run without any hiccups or any windows opening. For this, however, that pandoc window shows up. Am I doing it correctly? Is there any easy way to suppress the window and run the command in the background?
Runs a program without opening a window. The program is "cmd.exe", the windows command shell. It is invoked with arguments "/c time /t", which outputs the current time. It redirects the output to "c:\t.txt"
program
#a::
run cmd /c time /t > c:\t.txt, c:\, hide
return
output
c:\>type c:\t.txt
14:28
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)"
If I run a Perl script from a command prompt (c:\windows\system32\cmd.exe), how can I exit the command prompt after the script finishes executing.
I tried system("exit 0") inside the Perl script but that doesn't exit the cmd prompt shell from where the Perl script is running.
I also tried exit; command in the Perl script, but that doesn't work either.
Try to run the Perl script with a command line like this:
perl script.pl & exit
The ampersand will start the second command after the first one has finished. You can also use && to execute the second command only if the first succeeded (error code is 0).
Have you tried cmd.exe /C perl yourscript.pl ?
According to cmd.exe /? /C carries out the command specified by string and then terminates.
If you're starting the command shell just to run the perl script, the answer by Arkaitz Jimenez should work (I voted for it.)
If not, you can create a batch file like runmyscript.bat, with content:
#echo off
perl myscript.pl
exit
The exit will end the shell session (and as a side effect, end the batch script itself.)
You can start the program in a new window using the START Dos command. If you call that with /B then no additional window is created. Then you can call EXIT to close the current window.
Would that do the trick?
You can send a signal to the parent shell from Perl:
kill(9,$PARENT_PID);`
Unfortunately, the getppid() function is not implemented in Perl on windows so you'll have to find out the parent shell PID via some other means. Also, signal #9 might not be the best choice.
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.