Batch file: Pause does not keep the window open - windows

I made some batch files for builds etc, and some stay open until I press a key, some don't. Since the batch files are started on doubleclick from explorer, the last command always is pause.
This works:
#echo off
sencha app build testing
pause
This does not work:
#echo off
cscript /nologo newKey.vbs
sencha app build production
copy build\production\MyApp\app.js phonegap\www\
cd phonegap
cordova build android wp8
pause
Why does pause not wait for my keystroke here? Does it get any "keystroke" from the command before?
I am using Windows 8.1, if that matters...

Because cordova is cordova.cmd, a batch file, and when a batch file invokes another batch file the execution flow is transferd to the called batch but does not return to the caller
You will need to use the call command, so the execution flow returns to the caller
call cordova build android wp8

Related

Windows Command Prompt hangs after running batch file

I'm trying to setup a quick batch file where it sets up my development environment when run (on Windows 10). So far, all I'm doing is:
#echo off
w:
pushd directory_of_project
call build.bat //build project
call vsdbg.bat //run a batch file which opens up visual studio's debugger
call 4ed //Open my code editor exe
popd
Everything works fine, except after everything has been setup my command window hangs and I can't Ctrl+C out of it. The command prompt only finishes after closing the 4ed program. Is there a way to modify my batch file to prevent this from happening so I don't have to open up another command prompt window?
I figured it out:
#echo off
w:
pushd directory_of_project
call build.bat //build project
call vsdbg.bat //run a batch file which opens up visual studio's debugger
start 4ed //Open my code editor exe
popd

Syncing OneDrive (SkyDrive) with Batch File (via cmd)

Basically, I'm wondering if it's possible to sync OneDrive with a batch file. See, I can sync it whenever I go to File Explorer, right click on "OneDrive" on the left, and click "Sync," but I'm wondering if there's command windows has incorporated to have this exact same effect when used with a batch file. I have no idea what it is and have searched to no avail, so I hope that you can help me! Whatever it takes, I'm sure it would be an extremely simple script; the problem is finding out what command to use. Here's an example as a picture:
To shutdown OneDrive from the command line or in a batch file:
%LOCALAPPDATA%\Microsoft\OneDrive\OneDrive.exe /shutdown
To start OneDrive from the command line:
%LOCALAPPDATA%\Microsoft\OneDrive\OneDrive.exe /background
If the /background switch is omitted then Explorer is opened to the OneDrive folder in your user profile but OneDrive does not start.
If restarting OneDrive from a batch file then add the START command or the batch file won't end:
start %LOCALAPPDATA%\Microsoft\OneDrive\OneDrive.exe /background
Get my oneDriveSync.bat and test it.Be minded that it will work only if machine language is English.THe Sync is always the third verb but if it is inactive the third will be Pause so I cant create language independent version at the moment.
This is one simple solution:
Change OneDrive Settings to NOT Start automatically when Windows starts
Create a BAT file and launch OneDrive with Windows Task Scheduler during non-peak hours.
Create a .BAT file to Taskkill OneDrive.exe at the end of the Peak-hours:
Windows 10:
Command line to launch OneDrive (and automatically start syncing the folders/files in settings)
C:\Users\user\AppData\Local\Microsoft\OneDrive\OneDrive.exe
Command line to Taskkill Onedrive.exe
Taskkill /IM OneDrive.exe /F

Launch long running cmd as pre-build event in Visual Studio

I'm trying to launch a grunt process that will watch for .js file changes and transpile them into one file using grunt tasks. I can run it manually all day long, but I want to make it a pre-build so when a new dev gets the solution, building will launch the watcher. The problem (as you may have guessed) is that the grunt process stays running, so as a pre-build event, it never continues the build. I thought that using start would be asynchronous and would launch it without VS waiting on it to complete to continue the build, but I was mistaken. So, currently, my pre-build event is
cmd /c start $(SolutionDir)ProjectName.Web\run-grunt.cmd $(SolutionDir)
and run-grunt.cmd looks like
cd %1ProjectName.Web
grunt
This works but hangs until I close the cmd window which defeats the whole purpose. So, two questions:
Is this the wrong way to get this watcher kicked off?
Is there a way to structure these such that VS will launch the cmd and then resume the build without waiting for a return?
Have you tried setting your pre-build event to simply run a batch file that executes your current pre-build event? It seems like it will work because the batch file that Visual Studio executes will actually complete, leaving another command window in its wake.
I tested my theory with two batch files:
test1.bat
call "cmd /C start test2.bat"
echo test1
test2.bat
echo test2
pause
If you're still needing some parts of the grunt task to execute pre-build, you can break them out into separate tasks, so your pre-build event may end up looking like this:
cd $(SolutionDir)ProjectName.Web\
grunt build
grunt-watch.bat

bat script to check event viewer for error then run another bat to fix that error

I was wondering if one could use a bat script to check event viewer
for certain application errors, and if that error occurs, then it
should call another bat file.
for example...
i have a bat file called reset_IE.bat which clears IE temp files, and
resets it to factory default, which allready works.
how can i use cmd to check event viewer for a certain error, then run
the reset_IE.bat if necessray.
the main bat file will eventually contain many check for various
errors, for different software errors.
I found and example, with one of my users just now... where outlook keeps on asking for safemode and then restarts again... you need to delete outcmd.dat file...
How do i check eventviewer using wevutil.exe or any other util... to check application logs for Faulting application outlook.exe, and then call another bat file called something like fix_outlook_safemode.bat
which will in turn run
del "C:\Documents and Settings\%username%\Application Data\Microsoft\Outlook\outcmd.dat"
with windows2003 (maybe XP) you can use the built-in eventtriggers.exe utility
example this will execute raiseevent.cmd when a disk is full (eventid 2013 of source srv):
eventtriggers /create /TR "disk_full" /TK "C:\WINNT\system32\events\raiseEvent.cmd %computername% system 2013 Srv" /EID 2013 /SO "Srv"
As you can see you can transmit whatever parameters you want to the batch
with win2k8 and 7 you can create a task in the taskscheduler that will be trigger if an event occurs.

Weird Command Prompt hang when starting .exe from a batch file

I like to portable-ise as many programs / apps as I can, so I regularly create self-executing SFX archives that extract to %temp% and then run a selected file (usually the original .exe or, if necessary, a .bat file).
I'm trying to combine a x86 and x64 version of an app into one version, as I don't like having 2 files. So, I have 2 folders ("x86" and "x64") containing the different versions of the program and a .bat file in the root that will check the user's bitness and then launch the appropriate version. I'm having a few issues, though.
Here is my code:
checkandrun.bat
#echo off
goto Payload
:Payload
echo Checking architecture bit-type...
IF EXIST "%systemRoot%\SysWOW64" (
echo Your version of Windows is 64-bit [x64]
start "x64\GCFScape.exe" >nul
) ELSE (
echo Your version of Windows is 32-bit [x86]
start "x86\GCFScape.exe" >nul
)
echo.
echo Starting the appropriate version...
goto End
:End
echo.
echo This window will close in 20 seconds.
ping localhost -n 21 >nul
exit
If I use start then the original command window will exit correctly, as desired, but will open up a new, constant command window and the app won't launch.
If I don't use start the app will launch but the command window will stay open and won't progress past the line of code that was used to launch the .exe. If I close the app itself then the command window will proceed as normal to the exit command and close successfully.
Is there is a way around this? I've never had this kind of problem before.
Here is a link to the SFX archive in my Dropbox, if anyone wants to take an actual look at the environment and effects for themselves: https://dl.dropbox.com/u/27573003/Social%20Distribution/gcfscape182.exe
The docs for the START command say that the first arg that is in quote marks will be the title of the window. So, try this:
start /B "GCFScape" "x64\GCFScape.exe">nul

Resources