Solved

can  a file with .cmd extension be executed by a shell comman?

Posted on 2011-02-17
8
294 Views
Last Modified: 2012-05-11
Hello,
   I'm not exactly sure if the title makes sense or not but any input would be appreciated. Thanks
0
Comment
Question by:sn1fflez
8 Comments
 
LVL 8

Accepted Solution

by:
sharkbot221984 earned 167 total points
ID: 34917993
Yes. A plaintext file with a .bat or .cmd extension will be executed by the shell program -usually COMMAND.  Typically used for 'batch' scripting.
0
 
LVL 8

Expert Comment

by:sharkbot221984
ID: 34918008
Try it for yourself: create a new text file called 'test.cmd' (note you will need to be able to view extensions) with this content:

@echo off
echo test
pause

change the extension to .bat

you'll get the same thing.
0
 
LVL 1

Expert Comment

by:Kidwell_03
ID: 34918010
I agree with sharkbot221984.  Any plaintext file with a .bat or. cmd extenstion can be executed via powershell.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:sn1fflez
ID: 34918148
Thank you for the quick responses. Maybe you guys can tell me why the code below doesn't work?
retval = CStr(Shell("C:\Program\INT_Fortran_ComLink.cmd", 1))

retval is declared as string

Open in new window

0
 
LVL 5

Assisted Solution

by:rdhoore108
rdhoore108 earned 167 total points
ID: 34918322
I don't know Visual Basic very well, but I believe the problem is that you can't execute a cmd script, you need to execute it through cmd.exe:

retval = CStr(Shell("cmd.exe /c C:\Program\INT_Fortran_ComLink.cmd", 1))
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 34919900
==> Maybe you guys can tell me why the code below doesn't work?

Is that VB6 code that you are working with?  If so, I did think that you could initiate the BAT file directly from the Shell() function, without using cmd.exe.  What type of error or problem are you seeing?

~bp
0
 
LVL 19

Assisted Solution

by:Thommy
Thommy earned 166 total points
ID: 34930575
You can execute a batch script from a batch script by using CALL command as follows...

Call C:\Program\INT_Fortran_ComLink.cmd

0
 

Author Closing Comment

by:sn1fflez
ID: 35018353
sorry it took me so long to respond. I eventually got it to work and what you guys said helped a lot. Thanks
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question