Skip to main content

A simple tool to generate a call graph for calls within Windows CMD (batch) files.

Project description

# cmd-call-graph

[![Build Status](https://api.travis-ci.org/Microsoft/cmd-call-graph.svg?branch=master)](http://travis-ci.org/Microsoft/cmd-call-graph)
[![PyPI](https://img.shields.io/pypi/v/cmd-call-graph.svg)](https://pypi.org/project/cmd-call-graph/)


A simple tool to generate a call graph for calls within Windows CMD (batch) files.

The tool is available on PyPI: https://pypi.org/project/cmd-call-graph/

It takes the input file as stdin and outputs the resulting file to stdout,
outputting logs and errors to stderr.

Usage example from WSL (Windows Subsystem for Linux):

$ pip install cmd-call-graph
$ cmd-call-graph < your-file.cmd > your-file-call-graph.dot 2>log

The resulting `dot` file can be rendered with any `dot` renderer. Example with
graphviz:

$ sudo apt install graphviz
$ dot -Tpng your-file-call-graph.dot > your-file-call-graph.png
$ explorer.exe your-file-call-graph.png

## Example

Here is an example CMD script:

@echo off
call :foo
goto :eof
:bar
echo "in bar"
call :baz
call :baz
:baz
echo "in baz"
:foo
echo "In foo"
goto :bar

This script would generate the following graph:

![call graph](https://github.com/Microsoft/cmd-call-graph/raw/master/examples/example1-noshowall.png)

If the `--show-all-calls` option is set to `True`, then the following graph would be generated:

![call graph showall](https://github.com/Microsoft/cmd-call-graph/raw/master/examples/example1.png)


## Why?
Sometimes legacy code bases may contain old CMD files. This tool allows to
generate a visual representation of the internal calls within the script.

## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

## Unit tests
Run unit tests from the project root by running:

python -m unittest discover


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cmd-call-graph-0.4.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

cmd_call_graph-0.4-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file cmd-call-graph-0.4.tar.gz.

File metadata

  • Download URL: cmd-call-graph-0.4.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.9.1 setuptools/20.7.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.2

File hashes

Hashes for cmd-call-graph-0.4.tar.gz
Algorithm Hash digest
SHA256 68c75f2fdf42317031a1d3462427b66fbdf9dc92204546989cb1e31b1a400bec
MD5 2b6caf82f654fa7e171a0d52938e30ac
BLAKE2b-256 93b08918c9ee2aa86d30d9190370f0b6ee6394f81e3dedd822b4bb1534667168

See more details on using hashes here.

File details

Details for the file cmd_call_graph-0.4-py3-none-any.whl.

File metadata

  • Download URL: cmd_call_graph-0.4-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.9.1 setuptools/20.7.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.2

File hashes

Hashes for cmd_call_graph-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ff64c6a214f5537e76a60c83941c93fd2d60d7fc90dc1bf6430b6a5d6249f0b6
MD5 bc8e32d01d5057ad03024b83a58eca6e
BLAKE2b-256 80fba151f6ff2f455d5113611275759abc62c6f510e88bda91f90e63da409450

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page