I am running a batch script and outputting the info to a file in the temp folder, (just to learn from). I have an input for a user to select which mapped drive they want their data transferred out of. Here is what I have, it is super easy so I can learn then modify later. Cls @ECHO Off Net use &gt; c:\Temp\Map.txt Net Use Pause :Start  ECHO Which Drive letter do you want to back up? ECHO ? - Enter Drive letter ECHO E - Exit SET /P M=Make Choice then press ENTER: IF %M%==E Exit Else goto :here If %M%==e Exit Else goto :here  :Here Echo %M% Findstr &quot;OK           %M%:&quot; c:\Temp\Map.txt pause  What I need is to extract the path name for the drive they select. Like if there are 5 drives, and they want drive S: backed up, output is: OK           S:        \\10.X.X.X\Deployment\David\Davids_Scripts\bats  I would need the \\10.52.8.1\Deployment\David\Davids_Scripts\bats saved so I can put it in a transfer script.
3810
I'm looking to get the result of a command as a variable in a Windows batch script (see  for the bash scripting equivalent).  A solution that will work in a .bat file is preferred, but other common windows scripting solutions are also welcome.
121221
I have a web server that I want to map a drive to it. I want to do this in a .bat file. Pseudo ->   Check if a drive at an ip address has been mapped to a local drive.  If it has then progress with a reference to the drive If not map to a local drive and then progress with a reference to the drive  Is this possible and if so how can I achieve it?
57019
Normally we use a different file to redirect the output.  For example :  cat &lt; first &gt; temp   In this command the contents of first are redirected to temp instead of the standard output.  Then why does it truncates the file if I use the same file name?  Why can't it overwrite the same file?  cat &lt; first &gt; first
52196
I want to copy a directory from one place to another folder.   sudo cp is the command, but after that what should I type? The destination or source first?
59526
So I have a script that, when I give it two addresses, will search two HTML links:  echo "http://maps.google.be/maps?saddr\=$1\&amp;daddr\=$2" | sed 's/ /%/g'   I want to send this to wget and then save the output in a file called temp.html. I tried this, but it doesn't work. Can someone explain why and/or give me a solution please?  #!/bin/bash url = echo "http://maps.google.be/maps?saddr\=$1\&amp;daddr\=$2" |  sed 's/ /%/g' wget $url
110737
I want to get the result of time command into a text file but it's not working it only put blank space in the text file.  I already tried this commands,  A-  $ x=`time` $ echo $x &gt; log.txt $ cat log.txt  $   B-   $ time &gt; log.txt  real    0m0.000s user    0m0.000s sys     0m0.000s $ cat log.txt  $   C-  $ time &gt; log.txt 2&gt;&amp;1  real    0m0.000s user    0m0.000s sys     0m0.000s  $ cat log.txt  $    What I really want is this.   $ time &gt; log.txt $ cat log.txt  real    0m0.000s user    0m0.000s sys     0m0.000s
8187
Writing my first script so I'm sure this is a basic question, but can someone please explain to me why I can:  cd ~ cd bin cd ~/bin cd 'bin'   But not  cd '~' cd '~/bin'   I need to cd to a directory path with a space in one of the directory names, so I need the quotes (it's Windows Program Files under wine). I can get around it with two cd commands, but why can't I put ~ in quotes?  If I type cd '~' (or cd "~") I get:  bash: cd: ~: No such file or directory
100228
i Need a batch file to create a folder "test" in every removable device than i plug in my computer (pendrives and etc)  i am trying something like this  set "extDrive=" for /f %%D in ('wmic volume get driveLetter^ where drivertype=2 ) do set extDrive=%%D mkdir "%extDrive%\test"   Someone can tell me why this is not working ??
60629
I've been trying to keep some files in a separate folder as shortcut, so that I can keep track of my favourite media files and images etc in a specified folder as shortcut. I don't want to always copy these files everytime to that location so I was thinking of making it easier by adding a shortcut to the "send to" menu... I have windows 7 on my pc.  I'm trying to create a shortcut similar to the "send to Desktop (create shortcut)" that can simply place a shortcut in my "C:\Fav Media" folder, or similar location AS A SHORTCUT. Methods I had in mind:   Create a batch file that takes any file as input and creates a shortcut of that file in that folder. Thus any file can be dropped to the batch.bat.lnk shortcut and it's shortcut is sent to that folder. If file drop is successful, then I believe that send to option will do the same thing. I checked the "desktop (create shortcut).desklink" and it's extension is as already mentioned: .deskling.    I don't intend to play with registry, so if there's any file like a xml or txt or bat in windows that manages .desklink kind of extensions and does place shortcut from sendto menu no matter what the shortcut.desklink is named as, then maybe I could edit that xml and place the "C:\fav folder" as an addition in extensions to that xml with extension: ".favlink" ...  Is this possible? Can this be done in windows 7?  Thanks for any help.
80314
I am executing copy command from a function  execute 'copy (select * from tableName) to ''/tmp/result.txt'''   It works fine. But, tableName is dynamic and will be having more tables (iterating in a loop). result.txt is having only the last iteration (table) data.   I could do, if I had to, via the command line with \o or &gt;&gt; by appending to a file. But, I have to use the function.  I read .  It suggests a solution using temporary tables. Can I do something similar, but without temp tables? (I must avoid archive logs).  Will creating a temp table create archive logs?  Is there any way to do appending with copy command in a function?
30221
Suppose I want a bash command to do something extra.  As a simple example, imagine I just want it to echo "123" before running.  One simply way to do this would be to alias the command.  Since we still need the original, we can just refer to it by its exact path, which we can find using which.  For example:  $ which rm /bin/rm $ echo "alias rm='echo 123 &amp;&amp; /bin/rm'" &gt;&gt; .bashrc   This was easy because I was able to look up the path to rm using which.  However, I am trying to do this with exit, and which doesn't seem to know anything about it.  $ which exit $ echo $? 1   The command did not output a path, and in fact it returned a non-zero exit code, which which does when a command is not in $PATH.  I thought maybe it's a function, but apparently that's not the case either:  $ typeset -F | grep exit $ echo $? 1   So the exit command is not defined anywhere as a function or as a command in $PATH, and yet, when I type exit, it closes the terminal.  So it clearly is defined somewhere but I can't figure out where.  Where is it defined, and how can I call to it explicitly?
94277
In first.bat, I use  var5=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\x86_amd64\ CALL scripts\vc64.bat %var5%   And in scripts\vc64.bat, I use  SET var6=%1vcvarsx86_amd64.bat CALL %var6%   But I get : 'C:\Programvcvarsx86_amd64.bat' is not internal or external command..... error.  If the path assigned to var5 has no space, then it is fine.  I tried several combination of quotations and %1vcvarsx86_amd64.bat, but no change.  How do I make it works with path with spaces?    To be more precise, suppose it is C:\a b c\  In first.bat:       SET var6=C:\a b c\  =====&gt;  '"C:\avcvarsx86_amd64.bat"' is not.....`      SET var6="C:\a b c\" ====&gt;   There should not be a b      SET var6=C:\a\ b\ c\ ====&gt;    Can't find the specified path      SET var6=C:\a b c\ + Using "%var6" ====&gt; There should not be a b     Update: Here is an example. Change a b to ab works.  call.bat in C:\  @ECHO OFF  SET var5=C:\a b\ CALL C:\1.bat "%var5%"  pause   1.bat in C:\  @ECHO OFF  SET var6=%~1Test.bat CALL %var6%  RMDIR /S C:\NoWorry   Test.bat in C:\a b Test.bat in C:\ab  @ECHO OFF  RMDIR /S C:\ThereIsNoSuchFolder
79165
I need to create a batch file which starts multiple console applications in a Windows .cmd file.  This can be done using the start command.  However, the command has a path in it.  I also need to pass paramaters which have spaces as well.  How to do this?  E.g. batch file  start "c:\path with spaces\app.exe" param1 "param with spaces"
11052
I've got a long-running command that generates a lot of output on stdout. I'd like to be able to retain, for instance, only the last three days or the last gibibyte (avoiding cutting lines in the middle), and, if possible, in file chunks not larger than 20&nbsp;MiB. Each file chunk is being named with a numeric suffix or a timestamp.  Something like:  my-cmd | magic-command --output-file-template=my-cmd-%t \                        --keep-bytes=1G \                        --keep-time=3d \                        --max-chunk-size=20M \                        --compress=xz   Would write:  my-cmd-2014-09-05T10:04:23Z   When it's reaching 20M, it would compress it and open a new one, and so on, and after a while would it starts deleting the oldest files.  Does such a command exist?  I'm aware of logrotate and its ability to manage files written by other applications, but I'm looking for something simpler that doesn't involve having to set up a cron job, specify rules, suspend the process, etc.
100828
For use in a shell-script, I'm looking for a commandline-way to get the destination of a symbolic link. The closest I've come so far is stat -N src, which outputs src -&gt; dst. Of course I could parse the output and get dst, but I wonder if there is some direct way of getting the destination.
48151
When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of it , which describes a callable "wait.bat", implemented as follows:  @ping 127.0.0.1 -n 2 -w 1000 &gt; nul @ping 127.0.0.1 -n %1% -w 1000&gt; nul   You can then include calls to wait.bat in your own batch file, passing in the number of seconds to sleep.   (at last!). In the meantime, for those of us still using Windows&nbsp;XP, Windows 2000 or (sadly) , is there a better way?  I modified the sleep.py script in the , so that it defaults to one second if no arguments are passed on the command line:  import time, sys  time.sleep(float(sys.argv[1]) if len(sys.argv) &gt; 1 else 1)
96977
Say I have a file called calc.exe ( for example).  When I go to CMD and I run calc.exe it runs  because Windows has PATH settings in its environment variables.  Path information is  also accessible via typing path in cmd. ( as we all know).  Question  But - Is there any command in cmd that shows me information like this :   c:\&gt; locate_Where_It_Will_run_From calc.exe   Response :   c:\windows   I mean , the only solution which I see now is to run :   dir /s  calc.exe   And then to match results with the PATH information .  Is there any such command which will show me the information of my example above ?