Why this batch file not working? - Stack Overflow

Posted: Saturday, August 27, 2016 by Tyler Durden in

Why this batch file not working? - Stack Overflow



I'm trying to run a coursera-dl python script, using a batch file to avoid having to type the entire command line.
All I need to do is type the class name. e.g. science-of-meditation
But the script is not working properly.
Can someone please tell me what is wrong?
Emails and passwords have been omitted.
Filename : download_coursera.bat
Location of batch file: C:\Python\Python352-32\Scripts
@Echo Off
set /p Input=Enter Coursera name: 
python coursera-dl-script.py -u [email] -p [password] "%Input%"
So at the cmd, all I need to do is type this: science-of-meditation
If I run that command in the batch file on it's own in the CMD then it works (ie it downloads the files), but it doesn't download the files when i run in that batch file.
If you put this in the CMD, it would download the files from coursera.
python coursera-dl-script.py -u [email] -p [password] science-of-meditation
============

Here is the output when i run batch file with @echo off removed

Enter Coursera name: science-of-meditation
C:\Python\Python352-32\Scripts>python coursera-dl-script.py -u [removed] -p [removed]Input"
usage: coursera-dl-script.py [-h] [-u USERNAME] [-p PASSWORD] [--jobs JOBS]
                             [-b] [--path PATH] [-sl SUBTITLE_LANGUAGE]
                             [--download-quizzes] [--about] [-f FILE_FORMATS]
                             [--ignore-formats IGNORE_FORMATS]
                             [-sf SECTION_FILTER] [-lf LECTURE_FILTER]
                             [-rf RESOURCE_FILTER]
                             [--video-resolution VIDEO_RESOLUTION]
                             [--disable-url-skipping] [--wget [WGET]]
                             [--curl [CURL]] [--aria2 [ARIA2]] [--axel [AXEL]]
                             [--downloader-arguments DOWNLOADER_ARGUMENTS]
                             [--list-courses] [--resume] [-o] [--verbose-dirs]
                             [--quiet] [-r] [--combined-section-lectures-nums]
                             [--unrestricted-filenames] [-c COOKIES_FILE]
                             [-n [NETRC]] [-k] [--clear-cache] [--hook HOOKS]
                             [-pl] [--skip-download] [--debug]
                             [--cache-syllabus] [--version] [-l LOCAL_PAGE]
                             [class_names [class_names ...]]

You must supply at least one class name
shareeditdeleteflag

put on hold as off-topic by Ken WhiteSomethingDarkjebMofiStephan 19 mins ago

This question appears to be off-topic for this site. While what’s on- and off-topic is not always intuitive, you can learn more about it by reading the help center. The users who voted to close gave this specific reason:
  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, aspecific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Ken White, SomethingDark, jeb, Mofi, Stephan
If this question can be reworded to fit the rules in the help center, please edit your question.
   
You say "it doesn't work", but what exactly does that mean? Do you get an error message? If you remove the@Echo Off line, does the script run the commands you expect it to? – Blckknght 6 hours ago
   
it doesn't work is not a useful problem description. If you don't understand why, call your auto repair shop and say My car doesn't work. How much will it cost to fix it? and see if you get an estimate without providing much more detail. If you want help here, be specific about the problem you're having. If it doesn't work, tell us specifically how it doesn't work. What specific problem are you having? – Ken White 6 hours ago 
   
Sorry, i thought someone would try the script and can see for themselves.. By not working I mean it does not download the files when i run from the batch file, but it does download files when i put the same command in the CMD. – tyler.durden 1 hour ago    
   
I have updated the question and output of the error @ Blckknght. Seems like the input text in the cmd is not replacing the %Input% in the output and there is no space between word password and %Input% and my password looks like it has been truncated. C:\Python\Python352-32\Scripts>python coursera-dl-script.py -u [removed] -p [removed]Input" – tyler.durden 1 hour ago    
   
@mofi - no that is a valid class, I manage to solved the problem after trying a few things and finally found out the cause after a spark of insight. It was because my password had a character '%' which truncated the password and caused it to not replace %Input% with the input data. I changed my password to something with % in it and now it downloads. Your solution also looks like it might solved the problem, though I haven't tested this. But it looks like you on the right track. Thanks everyone for the help / input. – tyler.durden 39 mins ago    
   
do we need to mark the problem as solved? – tyler.durden 34 mins ago   
   
@mofi Why do we need to delete it? Won't this be useful for ppl who want to create a similiar batch file? Also howcome other Stack Overflow pages contains questions about batch files is allowed? e.g.stackoverflow.com/questions/1223721/… Also why does the tag : "batch-file" exists on stackoverflow if this is off topic to stackoverflow – tyler.durden 32 mins ago    
1 
Your problem was caused by a simple typographical mistake in batch code, i.e. you forget the missing double quotes. Run in a command prompt window cmd /? and read the output help. On last paragraph on last help page it is explained which strings must be enclosed in double quotes. Also there are already lots of questions and answers which are about a single percent sign in a parameter string which can be definitely found easier as this question with a title and a question text not being related to the real problem. Think about how somebody would need to search to find this question. – Mofi 22 mins ago
   
There is for example What is the difference between % and %% in a cmd file? I deleted already my two previous comments. I will delete soon also my remaining 2 comments. You have already got 5 downvotes and 4 close votes. So this question will be most likely closed within 24 hours and then is hidden for most visitors of Stack Overflow. Therefore I really think it would be better you delete it before it is done by Stack Overflow community. – Mofi 16 mins ago
   
@Mofi No my problem was not forgetting the double quotes, because even with the double quote, if the password had a % in it, it would still not work. I tested this. I understand the question is not very good, but I don't think I would have solved without having asked on this site. It never would have occur to me that % was the cause of the problem, so how i know to search about % on this site? How would you suggest to retitle the question so it is more suitable? Also is someone else allowed to delete this question or am I the only one allowed to choose to delete it or not? – tyler.durden 15 mins ago    
   
@tyler.durden For an answer on your last question read in help center the help topic Why and how are some questions deleted? – Mofi 8 mins ago
Please avoid extended discussions in comments. Would you like to automatically move this discussion to chat?

0 comments :