Quantcast
Channel: Active questions tagged windows - Super User
Viewing all articles
Browse latest Browse all 9663

How can I make a custom utility library with functions that will be callable from windows cmd?

$
0
0

How can I make a custom utility library with cmd/batch functions that will be callable from a windows cmd terminal?

You can make functions in a batch file, for instance:

@echo offgoto :main:say_hello  echo Hello world!goto :eof:main  call :say_hello

However, trying to call the function from cmd (after running the batch file in the same terminal) gives me Invalid attempt to call batch label outside of batch script..

The other way I know how to do this is to make each "function" its own batch file. But that is kind of ugly in the sense that if every function, no matter how tiny, has to have its own batch file, then it can lead to a huge number of files! I'd rather have all my cmd utility functions in a single file of a few hundred to a few thousand lines, than to have the code scattered among lots of tiny files.

In Linux, the way to do this is instead of running a shell script, you source it to expose the functions. Essentially I'm looking for the Windows equivalent of doing that.


Viewing all articles
Browse latest Browse all 9663

Trending Articles