I manage to get this command in my MacBook Pro Terminal Window :
IDL>
I am now in Text Wrangler. I type in print, "Hello World "
How do I get the words "Hello World" to appear in my MacBook Pro Terminal Window, from TextWrangler ? Do I have to save the file first ? What extension should I save it with ? Where would I save it ?
Thanks,
Tze
Easiest method:
Save your file as "hello_world.pro".
Start IDL from the same directory as the "hello_world.pro" file or do:
IDL> cd, 'directory/hello/world/is/in'
At the IDL prompt:
IDL> hello_world
Hello World
Eventually you will want to learn about !path, which will allow IDL to find your routines even if you are not in the same directory as the file.
You could have this in a script hello.pro
a='Hello'
b='World'
print,a
print,b
end
Then call:
IDL> .r hello
And it will print:
Hello
World
and a and b will still be active variables on the command line. .run scripts are very useful for starting programs.
Related
I am running Windows 10 and am trying to save the error output of a test.sh file to a text file.
So I created the test.sh file and wrote an unkown command in it (i.e. "blablubb").
After that I open the terminal (cmd.exe), switch to the directory and type test.sh 2>> log.txt.
Another window opens with "/usr/bin/bash --login -i \test.sh" in the title bar, shows me "bash: blablubb: command not found" and then closes immediately.
I want to save that output because the bash-window just opens for a split second. Every google search brings me to websites talking about redirecting the output and that Stream2 ist STDERR and therefore I should use test.sh 2>> log.txt or something smiliar that takes care of the STDERR stream.
If I try the same with a test.sh file and the content:
#!/bin/bash
echo hi there
I get the output in the briefly open bash-window:
bash: #!/bin/bash: No such file or directory
hi there
But the log.txt file is empty.
If I only have echo hi therein the test.sh file I get bash: echo: command not found in the bash-window.
The log.txt also empty.
If I type the following directly in the terminal, the output is written in the log.txt:
echo hi > log.txt 2>&1
If I type directly in the terminal:
echdo hi > log.txt 2>&1
I get 'Der Befehl "echdo" ist entweder falsch geschrieben oder konnte nicht gefunden werden.' in the log.txt file.
So I guess the redirecting of the output works fine until I use test.sh.
I know that .sh files are something from the unix world and that the problem might lie there but I don't know why I can not redirect the output briefly shown in the bash-console to a text file.
The 2>> redirection syntax only works if the command line containing that syntax is interpreted by bash. So it won't work from the Windows command prompt, even if the program you are running happens to be written in bash. By the time bash is running, it's too late; it gets the arguments as they were interpreted by CMD or whatever your Windows command interpreter is. (In this case, I'm guessing that means the shell script will find it has a command line argument [$1] with the value "2".)
If you open up a bash window (or just type bash in the command one) and then type the test.sh 2>>log.txt command line in that shell, it will put the error message in the file as you expect.
I think you could also do it in one step by typing bash -c "test.sh 2>>log.txt" at the Windows command prompt, but I'm not sure; Windows quoting is different than *nix quoting, and that may wind up passing literal quotation marks to bash, which won't work.
Note that CMD does have the 2>> syntax as well, and if you try to run a nonexistent windows command with 2>>errlog.txt, the "is not recognized" error message goes to the file. I think the problem comes from the fact that CMD and bash disagree on what "standard error" means, so redirecting the error output from Windows doesn't catch the error output by bash. But that's just speculation; I don't have a bash-on-Windows setup handy to test.
It would help to know if you are running Windows Subsystem for Linux (Beta). Or if you are doing something else. I'm assuming this is what you are doing on windows 10.
If this is the case are you using bash to run the script?
Are you using win-bash?
If it is win-bash I'm not very familiar and would recommend Windows Subsystem for Linux (Beta) for reasons like this. win-bash, while cool, might not be compatible with redirection operators like 2>>.
You have stdout and stderr, by default (if you don't specify) the >> (or append) will only append standard output into the txt file.
If you use 2 it will append the standard error into the txt file. Example: test.sh 2>> log.txt
This could be better described at this site.
To get exactly the command for append both stdout and stderr, go to this page.
Please tell me if this doesn't answer your question. Also, it could be more valuable to attempt a search for this answer first and explain why your search found nothing or give more extensive clarification as to what the problem is. I love answering questions and helping, but creating a new forum page for what might be an easy answer may be ineffective. I've had a bunch of fun with your question. I hope that I've helped.
That's makes a lot of sense. Thanks Mark!
Taking what mark says into account I would get Windows Subsystem for Linux (Beta). There are instructions here. Then run your script from there.
I have an extremely simple hello.rb file containing only:
print 'Hello world!'
I then try to run this file from my Ubuntu 14 terminal using:
ruby hello.rb
However, this ends up looking just about like this:
user#machine:~/Documents/Ruby/HelloWorld$ ruby hello.rb
Hello world!user#machine:~/Documents/Ruby/HelloWorld$
I guess that's technically correct, but it would be more readable if a newline is inserted after the output Ruby's execution. For regular terminal commands such as dir this newline is inserted, and the prompt starts on a new line.In other words, I'd like to see this:
user#machine:~/Documents/Ruby/HelloWorld$ ruby hello.rb
Hello world!
user#machine:~/Documents/Ruby/HelloWorld$
What do I need to change to get this behavior? Do I need to change the way I call Ruby? Or should I change my terminal settings?
Use puts instead of print. It adds the newline.
I am trying to start an IDL programme from the Windows command line.
Lets say I have the following programme:
PRO hello
print, "Hello, I am a IDL script!"
a=bytarr(100,200)
outname='g:\testimage.tif'
WRITE_TIFF, outname, a
END
I want to execute this programme using IDL -e .RUN from the command line as following:
C:\Users\lein_pa>idl -e ".RUN G:/05_Software/01_IDL/IDLWorkspace/Default/hello.pro"
IDL Version 8.2, Microsoft Windows (Win32 x86_64 m64). (c) 2012, Exelis Visual Information Solutions, Inc.
Installation number: xxxxx.
Licensed for use by: xxx
% Compiled module:HELLO.
C:\Users\lein_pa>
As you can see HELLO.pro will be compiled, but no message "Hello, I am a IDL script!" appears on the shell and also testimage.tif is not written to the disk. When I start this programme from the IDL IDE everything works fine.
Can please someone help me? What am I doing wrong?
You could keep the file with the same name, but change it to a batch-like file by commenting out the PRO hello and END since everything in your routine could just as easily be run from the command line.
Then to start everything, try:
C:\Users\lein_pa>idl -e G:/05_Software/01_IDL/IDLWorkspace/Default/hello.pro
On unix-based systems, this would start IDL and immediately run the batch file hello.pro. If you need the double quotes for a Windows based machine, then add those accordingly.
Keep in mind, if you make this routine more complicated but keep it as a batch file, then be careful with loops as you will need to use $ and & $ at the end of lines to include them in loops. I am quite certain that one could run actual programs/functions on startup, but it's just as easy to type in the function name after startup if it's necessary. Typically one wants to use a startup batch routine to set personal preferences/defaults that you wish to use or commonly use when in IDL.
I am trying to run my first Ruby program. I am using sublime. My programs code is as follows..
$ vim helloworld.rb
#!/usr/bin/ruby
# Hello world ruby program
puts "Hello World!";
I am getting the following output error...
C:/Users/myname/AppData/Roaming/Sublime Text
2/Packages/User/helloworld.rxml:1: `$ ' is not allowed as a global
variable name [Finished in 0.1s with exit code 1]
Can anyone help me, and google search did not turn up much.
Remove $ vim helloworld.rb from the file.
It's a common practice in the books to prefix the commands written in terminal with $, so if you see $ some_cmd, it's most probably written in terminal.
The headline should pretty much say it all. I'm using windows 7, installed cygwin, set it up, created a .rb-File which looks like this:
print "Test"
(Impressive stuff, eh?)
Now, using Cygwin, I want to execute it, I tried
chmod +x ruby.rb
afterwards
./ruby.rb
The following message comes up:
Unable to initialize device PRN
Any ideas?
Thanks!
You forgot the "she-bang" line. Without it it will be interpreted as a bash script, not a ruby script.
The print command that bash finds is Window's print.exe, which wants to print to a physical priner, rather than print to the screen.
Add "#!/usr/bin/env ruby" as the first line of the file.