Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

Question

Command Prompt Execute Different Extension

Aug 9, 2011 8:41AM PDT

Hi, Im creating a file extension, .agt that is a batch script.
How can I get cmd.exe to execute this script?

Discussion is locked

- Collapse -
Answer
(NT) And here I thought I needed to use cmd.exe /C foo.agt
Aug 9, 2011 8:54AM PDT
- Collapse -
---
Aug 9, 2011 11:33AM PDT

if executed "cmd.exe /c file.txt" you would expect the file to opened by notepad because that is the execute command for the open verb.
So if you execute "cmd.exe /c file.agt" the shell will attempt to open the file with the default application which in this case is not defined. cmd does not check the contents of the file so it doesnt know that it contains batch script.

I was\am hoping that that which instructs cmd that the file contains batch script is not hardcoded into cmd.exe but parameterised somewhere on the machine, probaby the registry.

- Collapse -
Well we have our ways.
Aug 9, 2011 12:15PM PDT

You can use the REG command to associate your file type with cmd. And use reg again to remove the association.

You can also put all the commands on the cmd line.

And finally did you try piping the file to cmd.exe?
Bob

- Collapse -
--
Aug 10, 2011 9:17AM PDT

"You can use the REG command to associate your file type with cmd. And use reg again to remove the association."

Just because a file type is associate with cmd doesn't mean that cmd will execute it as a batch script.

The file is executed wrt to the default value in the reg key HKCR\assoc\verb\command.
In this value you specify the execution command, eg "cmd /c %1 %*" which is straight back to my point in my previous post.

If you use explorer to create an association the default execution command is "program.ext %1" (ie no better than the cmd I mentioned above)

"You can also put all the commands on the cmd line."
Script is far too long, there is an upper limit on the number of chars that windows accepts on the command line. This limit is OS dependent.
Also the script is too complex. It would be impossible to escape the chars.

"And finally did you try piping the file to cmd.exe?"
Unless I am missing something, I dont see how that would work, cmd would need to read to the end of the pipe before it can do anything (goto statments,parsing etc).

- Collapse -
Then something is off with the requirements.
Aug 10, 2011 10:25AM PDT

We also have BATCH COMPILERS and no good reason to not name it .BAT or .CMD.

I'm just a programmer who started with the GE-210 and assembler and all the way to Android today.

Keep working on it. The only reason to not get it to work is we didn't keep an open mind.
Bob