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

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

Related

How to launch babun in a specified directory via the command line

now I'm currently using Visual Studio Code and I wanted to make the terminal use babun instead of the default cmd.exe
In fact, I have already managed to do that in theory - the problem is that, unlike with cmd.exe, the directory that I'm in upon starting the terminal is no longer the currently open project, it's just simply /home/myusername (i.e. a path in babun's directory tree).
This kinda sucks, since I don't really want to navigate to my directory every time.
Next, I also found out how to tell babun (in my case, zsh.exe) to use a default directory such as C:/ by adding cd /cygdrive/c to the end of .zshrc - Unfortunately, that's not what I want either, since I don't want babun to always use the same directory.
Now I figured that, seeing as this would be the most comfortable option with VSC*, there might be some console argument that tells zsh.exe to use a specific directory. Sadly, I couldn't find anything, hence this question.
Weirdly enough
Anyone know how to help me out? Appreciate the help :)
*VSC allows you to specify the path to your shell, as well as an array of arguments that will be passed.
You could place your directory into a cmd file and run it as a shell:
d:
#rem note that's important to change the drive 'permanently'
cd d:\home
zsh.exe
And then specify this cmd file as shell to invoke.
Open the desired directory in a file explorer, right click, then select Open Babun here.
Babun currently does not natively support a command line parameter specifying the directory to launch in.
However, there is a pull request in the Babun GitHub which solves the issue. Unfortunately, it doesn't seem to be likely to be accepted anytime soon, though.
To gain access to the feature manually, check out the pull request.

Why does one code execute from one folder but not the other?

I was just curious as to why with Windows O/S a simple Ruby file that prints one line to the command prompt can execute correctly from one path, but not the other.
Currently, I have said file in C:\Ruby193\test\lib saved inside the lib folder. When I go to the command prompt and set the path to C:\Ruby193\test\lib, I'd expect to see the code string be printed to the command prompt. However, nothing but an empty line is produced, and if I go up the path and set it to C:\Ruby193\test and execute the ruby file from there, it works just fine.
Does anyone have a sound explanation as to why it works that way? Would this also be the same case for a MAC O/S as well?

Windows, ClearCase, and Ant: how to handle directory slashes?

I have a Windows batch script that I use to build a module and the script in turn uses the ClearCase clearmake command to drive the actual compilations, directory creations and file manipulations, i.e. process the Makefile content. The batch script works flawlessly when invoked using a DOS window or from a "cmd /c ..." command line invocation. And it has been that way for some number of years.
I recently decided to move the script to Ant. The first step, out of simplicity, was to simply invoke the script unchanged using an Exec task (using cmd /c). Almost immediately, Ant fails while creating a directory. The error message reports something like:
mkdir: Cannot create the directory C:\\fred\\harry\\joe
I was able to verify that, using the DOS command prompt, the mkdir C:\\fred\\harry\\joe command works fine, so, as near as I can tell so far, Ant generating double backslash path separators combined with something inherent to clearmake and/or something in the Makefile is causing the failure.
The response I'm looking for is something along the lines: "Yes, clearmake is definitely the culprit because..." or "If you twiddle this thing or that thing in Ant, only a single backslash will be generated...". Should there be no simple and quick explanation, I will drill into the problem to determine what exactly is causing the failure.
Thanks,
I have seen similar error with:
dynamic views (more sensible to ownership than a snapshot view on C:\, which is your case)
resource handle conflict (the script tries to update a resource already taken by another process, which shouldn't be the case here with your script, since it was working outside of Ant Exec task)
error message (like you create a directory which already exists: the error get ignored in a classic script, while it could interrupt the ant task.
While the last cause is a good candidate, try first to simplify your script (leave only the mkdir for instance) in order to check that this line is indeed the issue (nd not "this line in conjunction with others actions taking place just before")

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.

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

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.

Resources