|
Answer» Hello,
I have created a command prompt shortcut that launches with a string of commands in addition to prompting for user input - however it is not accepting my variable. Could someone please assist me with a solution. The same code works in a batch and I have my reasons for using a shortcut RATHER than an actual batch.
Any help would be greatly appreciated.
Here is my code:
C:\Windows\System32\CMD.exe /k @ echo Address? & set /p Address= & ping -t %Address% Hello,
In further investigating the issue it appears the set command is taking my variable - however it seems the final command is not interpreting the variable. It is my GUESS quotation marks are needed somewhere in the final command and I have tried them in various places but have had no luck - below is the output when the shortcut is run - additionally I polled the variable in the same cmd instance to show the set command took.
Code again: C:\Windows\System32\cmd.exe /v:on /k @ echo Address? & set /p address= & ping -t "%address%"
Output:
Address? 127.0.0.1 Ping request could not find host %address%. Please check the name and try again.
C:\Windows\system32>ping -t %address%
Pinging 127.0.0.1 with 32 bytes of data: Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Ping statistics for 127.0.0.1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms Control-C ^C C:\Windows\system32>
Apologies for double posting.
Thank you for any assistance."C:\Windows\System32\cmd.exe /k @ echo Address? & set /p Address= & ping -t %Address%" Could try using " " as shown above to see if that helps as for spaces could be the issue. Unable to test from work computer.
Hello,
Thank you for your reply. When I encapsulate the entire string in quotes I receive an error that the path, file name, etc is invalid - basically the target becomes invalid.
I appreciate your effort.
I cant be certain but I think the quotes would wrap something - somewhere in the last command.
Also disregard the /v:on switch in my last post - I was pot shotting on my own.
Regardsyou cannot use set /p to get user input and use that variable in the same line like you are doing. The shell doesn't work like that. I can't get it to work like that either.
With delayed expansion you can set a variable and echo it in the same line - but it just doesn't seem to play right on the command line side of things.
Code: [Select]@echo off setlocal ENABLEDELAYEDEXPANSION set /p "var=Enter TEXT: "&echo !var! PAUSE Thank you all for your replies. Salmon, judging from my output - I think your right - thank you. Since your post I have tried to add in a break or some other line command magic to simulate a line break but so far have had no luck. You did at least discover my problem.
Thank you again.This may be some use; it creates & runs a batch script in the system temp folder; I can't make it delete the batch after you interrupt ping -t with CONTROL-C
Shortcut target:
C:\Windows\System32\cmd.exe /k @echo @echo off > "%temp%\mytemp.bat" & echo set /p Address="Address? " >> "%temp%\mytemp.bat" & echo ping -t %Address% >> "%temp%\mytemp.bat" & "%temp%\mytemp.bat"Thank you Mr. Trout - I had thought of going that route also. The problem is I work from a corporate laptop and it is pretty picky about batch files (among other things) from being created or executed under my user. This is my main reason for doing this as a shortcut. I almost had it. Like you said - it does take my variable - it just doesnt like to use the variable on the same line - until i can find a way to trick into thinking there is a line break, I will just have to re-enter the ping command on a new line for the time being.
In my line of work I ping routers many times a night and the fewer key strokes or clicks the better. My premise was to copy the ip, launch the shortcut, paste the ip, and a control+c to stop. That's it - from there I either fix the problem remotely or wake up someone who makes more money than I do.
Many thanks for your help just the same.Can you create a shortcut to run in your profile folder, and open a cmd prompt. Create a second shortcut called a.lnk in your profile folder with a command line of ping -t %a%
When you start the first shortcut type set a=192.168.1.1 where you paste the ip address and then type a.lnk to launch the link, which may then ping the IP address if it inherits the environment from the cmd prompt.
If it doesn't get a copy of the enviroment then setx can set a master enviironment variable - if you have access to it.
Just thinking out loud here...I tested it and it does work, but it's not saving keystrokes.
You could have a shortcut to a cmd prompt and just type ping -t and paste your IP address in.Are you able to add an executable to your desktop, and create a shortcut to it?
This 7kb executable is a compiled Purebasic script - see below in blue. It gets an IP address and launches ping -t with the IP address.
http://www.astronomy.comoj.com/p.exe
OpenConsole() Print("Enter an IP address or URL: ") a$ = Input() result = RunProgram("ping.exe","-t "+a$,"")
|