Batch Scripts - Need to specify to use an ANSI console and execute a command - ruby

This is a noob question at its best but Google isn't finding what I need.
I have a ruby script that I need to fire off via task scheduler. I thought I did it right by using the following:
cmd /k ruby test.rb
This works when starting the .bat file from the folder. However, if it runs from taskeng.exe it fails because its looking in my system32 folder. I don't want it to run from system32 so how do i format this to run from say, c:/dev/
Again, sorry for the extremely noob question.

You can leave out cmd of that and just use
ruby test.rb
or rather (in your case):
ruby C:\Users\Foo\test.rb
or something like that. Giving the complete path to the script usually helps in finding it ;-)
In any case, if you need the working directory you can set it in the scheduled task itself. Something akin to the following:
       
Likewise, if you actually need cmd in there. Just fill out the Start in field and you have a working directory.

Related

Running python script on CMD which uses a folder to output results

I was using Pycharm as my editor to run the scripts since i need to add a task scheduler i had to test the code on the command prompt. Firstly this is the structure of my project.
When i try to run the following line
C:\Users\My_name\AppData\Local\Programs\Python\Python36-32\python.exe "C:\Users\My_name\PycharmProjects\FYP_CB006302\generateSummary.py"
I get this error,
From the knowledge i have i think it is because it doesn't recognize the path.
But when i change the directory to my project folder then give the path to python.exe and type generateSummary.py it works which was done as shown here.
However i highly doubt that this method can be used to task a schedule in Windows. Therefore, any ideas that would to run as shown in the beginning will be helpful.
The problem here is that when you use that line to run a particular script the folder which is causing the error is out of scope.
C:\Users\My_name\AppData\Local\Programs\Python\Python36-32\python.exe "C:\Users\My_name\PycharmProjects\FYP_CB006302\generateSummary.py"
In this case pickle_saves folder is out of scope. You can avoid this by giving a absolute path to that file in line 173. Where the absolute path is something like C:\user\documents\projects\pickle_saves\all_words

How to create an executable command prompt script

I usually perform actions in the 7zip command line program. I was thinking about creating a small script to do everything automatically, but I have never written any Windows shell script before and therefore don't even know where to begin.
I would like to make an executable script file which, when a user double-clicks on it, will call the 7zip command line and perform some actions.
First of all, is this possible? And if it is, what is the best way to do this?
You can create a batch script to do this.
It's basically command line commands that run one after another so you don't have to keep typing them in :)
Put the commands you would normally use for 7zip in a notepad file and save it with the extension .bat, then run it.
7z blah blah params
7z more params and args
All your commands will be executed automatically when the previous one finishes.
There are other programming languages you could do this in (or even VBScript) but batch would be perfectly suited to this, and you don't need to install anything extra.
Batch files can run a series of command line commands. Simply create a text file and name it with the .bat extension.
There are plenty of resources on the internet which will provide you with help.

How to get files and directories set up for Ruby?

I am doing prep work for App Academy but I am having a hard time setting up files/directories to be able to run everything correctly. I have a couple questions and haven't been able to find concrete answers:
How do you make a directory in the windows terminal?
How do you run files previously written in Notepad in IRB? I wrote some simple scripts in Notepad because Sublime was causing me severe migraines. Or how do you change Notepad files to Ruby files?
How do you create new files in IRB like test_code.rb?
1) When at the Windows command prompt and having navigated to your working directory, type md directory_name
2) Unless you have specifically told notepad otherwise, notepad will have saved your file as a .txt file. You will simply have to rename the file extension from *.txt to *.rb.
3) When you installed Ruby on your Windows machine, the Ruby interpreter would have undoubtably been added to your path, so you should just be able to run your *.rb file direct from the windows cmd prompt and it will execute.
To load it while in IRB: Make sure you run IRB from the same folder as your *.rb file is in. Once you have cranked up an IRB session, type load 'my_file.rb'.
IRB is a great environment for testing code, but not for writing full scripts. Use Notepad or Notepad++ or Vim for Windows or your editor of choice, as long as it's capable of generating a text (non word processing document).
You can make a directory in the terminal or in the Explorer, it doesn't matter. Just note where you created it so you don't lose it.
If you want to run a script in Ruby, simply type ruby /path/to/the/file/script_to_run.rb and the Ruby interpreter should load and run the file.
You can load a script into IRB and watch it run, but that's rarely something we need to do. More often you'll want to run scripts using Ruby, and try things in IRB, since it's like a scratchpad.

From within a Rhino JS console run CD produces exception

When attempting runCommand("cd", "..") from inside a js.jar console an IOException is thrown.
I believe it's because in the command prompt the CD command is actually built into the console and not a separate .exe file. The runCommand("notepad") works fine, and that .exe can be found on the classpath in the usual location.
Is there a work around for this?
I was thinking that changing the directory through java instead of through the command prompt it might solve this problem, but I don't recall how to do that from java, but I plan on trying to figure that out.
To sum up: Is there a way to run "cd" from within a Rhino JS console on windows?
Thanks,
L-
Multiple issues to solve here; it depends what you are trying to do.
runCommand actually runs executable programs. cd is not an executable on Windows; it is a command in the command shell. So you would need to execute something more like this:
runCommand("cmd","/c","cd <target-directory>")
However, the underlying Java runtime does not allow you to actually change the working directory anyway. See this StackOverflow discussion. So shelling out cd just changes the directory for the subprocess (the process running cd), which is probably not what you want.

Any way to interpret a command without running cmd.exe?

I am looking for a way to run an executable or a script without getting cmd.exe to do it for me. Currently I'm launching a process using cmd.exe /C <command>, which I need to do the following things for me:
Look for the executable file in the current directory and PATH
Interpret PATHEXT to permit extension-less script commands
Interpret file associations to, e.g., run the python interpreter when I tell it to run blah.py.
I don't need to be able to run any of the "built-in" commands, like "dir".
Is it possible to avoid using cmd.exe without essentially re-implementing all of the above functionality? There must be some sort of shell API to do the above things, right?
ShellExecute should do exactly what you want - you can use it to launch an executable or a file (which is then opened with the standard application),
http://msdn.microsoft.com/en-us/library/bb762153%28v=vs.85%29.aspx
Take a look at System.Diagnostics.Process.Start( appName, args) .
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx and about the shell, have you looked it: http://msdn.microsoft.com/en-us/library/bb773177(v=vs.85).aspx ?

Resources