Dead Men Walking

dMw Chit Chat => The Beer Bar => Seriously though ... => Topic started by: Wordan on June 15, 2006, 04:12:01 PM

Title: Batch scripts?
Post by: Wordan on June 15, 2006, 04:12:01 PM
Can I write a batch script that will take an argument and pass it to another program like so:

>rubytest.bat "c:\path\to\script\to\test"

and have it run ruby.exe "c:\path\to\script\to\test"?

I have been searching for tutorials but can't find anything to do with passing arguments.

I want to run it with a batch script so I can stop the command line window from closing when the ruby program stops running. Are there other ways to do this?

Thanks
Title: Batch scripts?
Post by: suicidal_monkey on June 15, 2006, 04:20:16 PM
I've not done that with a batch command before...not sure if these ideas will help you but...

if you run ruby.exe from a cmd window (start-->windows-->run "cmd") the window remains open after ruby closes.

Are these programs you have written? If so there are simple ways to stop a "dos" program closing it's window when it finishes by forcing it to request a char input (i.e. press any key) before finishing?
Title: Batch scripts?
Post by: Anonymous on June 15, 2006, 04:24:14 PM
Have you tried file redirection? Something like:

rubytest.bat > output.txt

ruby.exe < output.txt

More info at:

http://www.microsoft.com/resources/documen...h.mspx?mfr=true (http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/batch.mspx?mfr=true)
Title: Batch scripts?
Post by: Wordan on June 15, 2006, 04:26:47 PM
QuoteOriginally posted by suicidal_monkey@Jun 15 2006, 03:20 PM
I've not done that with a batch command before...not sure if these ideas will help you but...

if you run ruby.exe from a cmd window (start-->windows-->run "cmd") the window remains open after ruby closes.

Are these programs you have written? If so there are simple ways to stop a "dos" program closing it's window when it finishes by forcing it to request a char input (i.e. press any key) before finishing?
[post=131821]Quoted post[/post]
[/b]

It's for debuging ruby scripts, so I get to see the error messages without the window closing. I want to use a batch script so I can call it from Notepad++
Title: Batch scripts?
Post by: suicidal_monkey on June 15, 2006, 04:29:42 PM
QuoteOriginally posted by BlueBall@Jun 15 2006, 03:24 PM
http://www.microsoft.com/resources/documen...h.mspx?mfr=true (http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/batch.mspx?mfr=true)
Perhaps the CALL command is what you're after?
http://www.microsoft.com/resources/documen...l.mspx?mfr=true (http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/call.mspx?mfr=true)
Title: Batch scripts?
Post by: Anonymous on June 15, 2006, 05:43:28 PM
QuoteOriginally posted by Wordan@Jun 15 2006, 03:26 PM
It's for debuging ruby scripts, so I get to see the error messages without the window closing. I want to use a batch script so I can call it from Notepad++
[post=131823]Quoted post[/post]
[/b]
In that case rubytest.bat "test script" > output.txt may do the trick? Worth a try?

Alternatively, see the bit about "Command Redirection Operators" in the link I gave - here is direct link.

http://www.microsoft.com/resources/documen...edirection.mspx (http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/redirection.mspx)

I am thinking of something like this in particular:

QuoteThe & redirection operator duplicates output or input from one specified handle to another specified handle. For example, to send dir output to File.txt and send the error output to File.txt, type:

dir>c:\file.txt 2>&1
Title: Batch scripts?
Post by: Wordan on June 15, 2006, 08:19:06 PM
Thanks guys. My dos knowledge doesnt really extend beyond dir and cd. So a lot of that stuff looks very cryptic to me  :unsure:

But I found what I wanted there, the whole %0 - %9 thing.
%0 is the path of the batch script and %1 and up are paremeters you added

Thus my rubytest.bat script is as follows:

@ECHO OFF
ruby %1
pause

A complex and thorough program that demonstrates my accomplished windows cmd skills very well.

Notepad++ calls rubytest "path to file im working on" when I press the run button and when my ruby script finishes runing or crashes with a bunch of errors I get to see them without the dos window disapearing untill I press the 'any key' as requested by the pause command in the batch script.

A satisified customer, thanks again   :D
Title: Batch scripts?
Post by: Anonymous on June 15, 2006, 09:28:29 PM
Glad to be of service :)

But don't really think I helped  :blink:  :roflmao:
Title: Batch scripts?
Post by: Knabbel on July 07, 2006, 01:11:16 PM
For batch scripting I can advise you guys the following website.....

Batch scripting + examples (http://www.robvanderwoude.com)

Good luck.