0

I was trying to add a tracert command to a .bat file.

At the cmd.exe I was writing:

tracert 111.111.111.111 > desktop\tracert.txt

and it ran ok. I've created a bat file like this:

::@echo off
Cd C:\
cls
echo %DATE%
echo %TIME%
set datetimef=%date:~-4%_%date:~3,2%_%date:~0,2%__%time:~0,2%_%time:~3,2%_%time:~6,2%
echo %datetimef%
::2013_04_20__13_01_47
::tracert 111.111.111.111 > desktop\Tracert_IP1_%datetimef%.txt
tracert 111.111.111.111 > desktop\tracert.txt

The idea is to add the data to filename, I also would like to write it inside the tracert.txt, but I dont know how.

Code result:

C:\>echo 20/04/2013
20/04/2013

C:\>echo 14:18:12,44
14:18:12,44

C:\>set datetimef=2013_04_20__14_18_12

C:\>echo 2013_04_20__14_18_12
2013_04_20__14_18_12

**C:\>tracert 111.111.111.111  1>desktop\tracert.txt**
**The system cannot find the path specified**

Why is it adding "1" before the ">" and removing the space between ">" and "desktop"?

Anyway, I tried to run the tracert command again directly at the cmd but now it is giving me the same error message as the bat file: The system cannot find the path specified

Edit 1: Well, the problem with the path not find is because I've changed the cmd path using "cd" command, than the desktop folder was just not found! I'm embarrassed! Sorry guys.. Thanks for the replays about the "1"s and disapearing withe spaces.

  • 1
    To remove all ambiguity why not specify the full path, with quotes if required? – Karan Apr 20 '13 at 17:34
  • I'd probably use %USERPROFILE%\Desktop – unknownprotocol Apr 20 '13 at 19:35
  • You are right! Dumb problem.. sorry – Pedro77 Apr 21 '13 at 21:54
1

The place you know as desktop is a subfolder of your user profile that has the same name. If your batch file is stored on your desktop then simply remove the desktop\ part of the output. When you run cmd its base directory is your root user profile directory which has your desktop folder below that. If you create a batch file and run it then the base directory that cmd works in is that directory and not your user profile.

If you want your batch file to always output to your desktop irrespective of where it is stored then the cmd environment has a variable USERPROFILE that points to your profile directory (C:\Users\yourUserName) and can be combined with \desktop to output files to your desktop.

Where you have

tracert 111.111.111.111 > desktop\tracert.txt

Replace it with

tracert 111.111.111.111 > %USERPROFILE%\desktop\tracert.txt
  • Yes, that's what I'd say. Alternatively, one can also create an environment variable for this user's desktop folder... so it can be accessed via for ex: %DESKTOP% – unknownprotocol Apr 20 '13 at 19:37
3

"Desktop" in this case is relative path. You should change to right folder ("cd" command) or put the whole path to output file in the .bat file.

  • If the path contains spaces - you should specify the whole path surrounded by "". – pbies Apr 20 '13 at 20:29
1

1> is STDOUT, as opposed to STDERR, which is 2>

I think the space is just a syntactical issue, cmd.exe doesn't like the whitespace, so it changes it.

See Microsoft's Command redirection page for more info.

As to the not found error, checking permissions in that directory would be my first suggestion.

PS: Not a win user anymore, but is 'desktop' a valid way of accessing the desktop, or is it a directory name?

  • I realizy that I was very dumb! Lol... When you start cmd it starts by default at the Users\UserName folder! I changed the cmd path usind "cd".. LOL! sorry! – Pedro77 Apr 21 '13 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.