|
Answer» I am running Windows Vista Ultimate SP2 with MS DOS Version 6.0.6002
Okay, I have some experience in C/C++ and Java, but I am a total n00b when it comes to DOS.
What I WANT to do is create new DOS external commands for GNU programs I have downloaded, so that I don't have to type out the entire path to the executable each TIME I want to use the program.
For instance, I want to create a command for Wget so that I can just type wget instead of "C:\Program FILES\GnuWin32\bin\wget.exe"
I'm pretty sure this is possible in Linux bash because I remember watching someone do it about a year ago. I just can't remember the command they used or its MS DOS equivalent (if there is one).
I tried making a batch file wget.bat to put in C:\Windows\system32, but this code is limited to only 8 arguments and I might need more: Code: [Select]@echo off "C:\Program Files\GnuWin32\bin\wget.exe" %1 %2 %3 %4 %5 %6 %7 %8 %9
I tried to write a C program to get around the argument limit (or at LEAST make it larger). Of course, it's been a while since I wrote in C and the program below keeps crashing for some inexplicable reason: Code: [Select]#include <stdlib.h> #include <process.h>
int main(int argc, char *argv[]) { int i; char *command = ""; strcat(command, "\"C:\\Program Files\\GnuWin32\\bin\\wget.exe"); for (i = 1; i < argc; i++) { strcat(command, " "); strcat(command, argv[i]); } system(command); return 0; }
I'm willing to bet that there's an easier way to do this besides making a full-blown C executable, but I just don't know how to do it and I seem to be failing to find it in my internet searches.
If anyone knows any way at all I can create new External Commands in MS DOS, even if it's as convoluted as a C executable, please let me know. I thank you all very much for your assistance.try use this:
Code: [Select]@echo off
call :getallargs some random args 123 asd
echo %args% pause exit
:getallargs :LOOP set args=%args% %1 shift if not "%1" equ "" goto LOOPC:\>type wget.bat Code: [Select]@echo off start "C:\Program Files\GnuWin32\bin\wget.exe"
C:\> or
C:\>type wget.bat Code: [Select]@echo off start "C:\Program Files\GnuWin32\bin\%1.exe"C:\>wget.bat wget C:\> Excellent. I was not quite sure how to use the shift command until you POSTED this code. With a little modification, I now have a standard template for creating new external commands by creating batch files in C:\Windows\System32
Code: [Select]@echo off set args="C:\Program Files\GnuWin32\bin\wget.exe"
:LOOP set args=%args% %1 shift if "%1" neq "" goto LOOP
%args% set args=
It runs perfectly. Problem resolved. Thank you devcom! or, instead of
Code: [Select]@echo off "C:\Program Files\GnuWin32\bin\wget.exe" %1 %2 %3 %4 %5 %6 %7 %8 %9
have
Code: [Select]@echo off "C:\Program Files\GnuWin32\bin\wget.exe" %*
|