Computer Hope
Microsoft => Microsoft DOS => Topic started by: 037 on March 31, 2010, 07:06:40 AM
-
how can i get the hostname from a workstation and make a folder named the same as the workstation? i have tried "setlocal, set hostname=%hostname%, endlocal".
or in other words, "hostname" is a command. how can i make a file from the output of a command?
xpp sp3.
i am trying to backup multiple folders to one folder with the name of the workstation it came from.
-
Im assuming you mean appending to a file, when you say "make a file from the output of a command"
> Clears the file
>> adds a line to a file
example:
echo hello>>myfile.txt
-
i am trying to go to a workstation and run my batchfile. it needs to find the computer name and make a file with the name of the workstation. then it will backup some folders and save them under the folder that it just created with the computer name so i can find it later to restore them. i have the batch file created and it can store folders under the %username% variable, but i would much rather have it store under computer name.
example: when i type "echo %username%" in a cmd it displays my user name. but when i type "echo %hostname%" it does not display. i can however type "hostname" by itself to get the workstation name....
thanks in advance...
-
on your command prompt, type
env
. You can see computer name there.
-
env does not work. isnt that for linux? i need to create a folder with the name of the pc...
-
ComputerName is a system variable that you can use:
md %computername%
OR
You can still use the hostname command in a batch file:
@echo off
for /f %%a in ('hostname') do (
md %%a
)
Good luck. 8)
Env works on WinXP but you can also use set to list all the environment variables.
-
@echo off
md c:\%computername%
or if you want to name a file:
@echo off
echo. >> c:\%computername%.txt
-
thank you both, i ran the set comand to see the variables but "computername" was not in there. but it does work with computername so thanks again...
-
"Hostname" is a command. How can I make a file from the output of a command?
C:\>type thirty7.bat
@echo off
hostname > host.txt
type host.txt
pause
md Okie
cd Okie
echo hello okie > host.txt
type host.txt
Output:
C:\>thirty7.bat
Okie
Press any key to continue . . .
hello okie
C:\Okie>
-
another greg
-
another greg
I already sent a PM to Nathan... >:(
-
on your command prompt, type env
. You can see computer name there.
I use XP pro SP3 and there is no env command.
-
I use XP pro SP3 and there is no env command.
Here.