?
Solved

Pass variable file path to batch file?

Posted on 2007-11-15
6
Medium Priority
?
1,953 Views
Last Modified: 2012-08-13
I need some help passing a variable to a batch file, specifically the path of a file.  My batch file looks something like this:
net use lpt2:  serverdesignjet
copy /b filename.plt lpt2
net use lpt2: /delete

It would be great if users could just drag a .plt on to this batch file and have it run.  Currently the have to move the .plt file and rename it, which as you can imagine isn't very fast.

Thanks!
0
Comment
Question by:KPS2007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 30

Accepted Solution

by:
SteveGTR earned 400 total points
ID: 20292091
Could do this:
@echo off
 
setlocal
 
set fileName=%~1
 
if "%~1"=="" set /p fileName=Please enter file name to processing: 
if "%fileName%"=="" echo Processing aborted&goto :EOF
if not exist "%fileName%" echo File does not exist&pause&goto :EOF
 
net use lpt2:  serverdesignjet
copy /b "%fileName%"  lpt2
net use lpt2: /delete 

Open in new window

0
 
LVL 9

Expert Comment

by:MSE-dwells
ID: 20292134
SteveGTR: are  you loving' this new 'code-snippett' feature or what? ;0)
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 20292150
Yes I am.

Although it does appear that some users attempt to paste the line numbers with the code. You can do it by starting the drag at the numbers. One user insisted it was a bug and asked if I would repost the code in a message.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Closing Comment

by:KPS2007
ID: 31409418
This snippet helped me get it running the way I like, thanks!
0
 
LVL 9

Expert Comment

by:MSE-dwells
ID: 20292185
ROFL, that cracks me up ... and so you can!  Perhaps EE could consider rendering them in a way that they can't become part of copy/paste op (or even provide a download this as a "TEXT" file button).
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 20292374
That's a good idea. Because if one user can do it you know that more users can.
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Six Sigma Control Plans

649 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