Misbehaviour of Applescript: tell application "Terminal" to do script - osx-lion

On MacOS 10.7.5, the following Applescript
tell application "Terminal" to do script "echo foo"
opens a new Terminal window but foo is not printed. Using the command echo is nothing special, I can't get any command executed at all (I found the bug as I tried to have the command cd executed). I found a workaround:
tell application "Terminal"
do script
do script "echo foo" in window 1
end tell
Am I missing something? Or is it the expected behaviour?

I would just use:
do shell script "echo foo"
But, if you want the response of the shell script, you can use:
set shellresponse to do shell script "echo foo"

Related

Perl keeps flashing when running command Windows 10

I have installed Perl but every time I run a command it flash and goes away and does nothing, I have added it to Environment path and gave full permission to folder Perl64
edit regeristy in perl command c:\perl\bin\perl.exe %1 %*
when I run Perl -v I do get versions so I know it installed
It sounds like your command ran to completion and exited. Once the program exits, the console is closed.
Perhaps you are getting an error. You should run the program from the command line to see what errors you get.
You could also try associating the file with the following command:
cmd /c c:\perl\bin\perl.exe %1 %* & pause
(Untested)

AutoHotKey run command in background

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 do I tell eclipse that an external tool is done executing?

The Eclipse IDE has a feature where one could run external tools. I use it to run batch scripts. Oddly if a batch script runs a powershell command, the powershell command will never exit until I hit enter. This is especially odd since it exits just fine when running in cmd. How should I correct my script so that it runs as expected via the eclipse external tools?
Current script (foo.bat):
#echo off
echo "Hello 1"
REM Configure this to your installation of maven.
SET "CMD=C:\foo.ps1"
REM Reformat args to be Powershell friendly.
SET "ARGS=%*"
SET "ARGS=%ARGS: =' '%"
PowerShell.Exe -Command "%CMD%" '%ARGS%'
echo "Hello 2"
EXIT /B
In cmd, I see "Hello 1", the output of %CMD%, and "Hello 2". In Eclipse, I see "Hello 1", the output of %CMD%, and then it hangs in the progress tab forever until I click the Console window and press the enter key.
I tried passing the -NonInteractive flag to Powershell. I tried having my Powershell script echo a newline at the end. Not sure how to get this to "just work".
Found the answer. I needed to add a NUL redirect to the end of my Powershell command. So it looks like this:
#echo off
REM Configure this to your installation of maven.
SET "CMD=C:\foo.ps1"
REM Reformat args to be Powershell friendly.
SET "ARGS=%*"
SET "ARGS=%ARGS: =' '%"
PowerShell.Exe -Command "%CMD%" '%ARGS%' < NUL
Note that I also removed the dubugging code from the script found in my question. If you add that code back in, you'll see that it echos everything now.

Unable to open a second command window from batch file

I have following command to start after other which does not depend on each other. However, with following command, I only can start #1, #2. My command #3 does not start .
I would like to know if i have make any mistake. I did not see the the third line executed.
// make a directory
// startd adb logcat
// shell adb monkey
"test.bat"
mkdir c:\test_log_file
START "powershell Window" powershell adb logcat >> "C:\Testdata.txt"
START "Powershell Window 2" shell adb monkey -p com.android.browser
Based on your earlier question (how to open power shell window from a batch file to a new window), I'm assuming that "shell" is a command you have available to you, and not a typo. Two possibilities come to mind:
Is "shell" in the path? If not, you need to provide the full path to this command. (Probably not the answer, because if this were the issue you'd get a popup error message telling you that Windows can't find "shell".)
Although you've titled the window "Powershell Window 2" in your second START command, this command should actually open a cmd window, not a powershell window. Are you looking for a new powershell window, when you actually have a cmd window that's titled "Powershell Window 2"?
If you want to start a powershell window, the command should be:
START "Powershell Window 2" powershell -noexit shell adb monkey -p com.android.browser

How do I exit the command shell after it invokes a Perl script?

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.