Topic: Sleep (for pausing commandline)  (Read 8580 times)

Sleep (for pausing commandline)
« on: October 22, 2010, 09:29:14 AM »

Galapo

  • Gena Baker
  • Grand Chef
  • *****
  • Location: Australia
  • Date Registered: Sep 2010
  • Posts: 2207
« Last Edit: October 22, 2010, 09:32:56 AM by Galapo »

Re: Sleep (for pausing commandline)
« Reply #1 on: November 13, 2018, 09:35:32 AM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 10350
Hi Galapo,

can we have cmd title countdown with sleep with seconds

eg.
sleep.exe -Title

 :cool:

:turtle:

edit:
better:

sleep.exe -Titlemmss

to show minutes and seconds
« Last Edit: November 13, 2018, 09:48:13 AM by Lancelot »

Re: Sleep (for pausing commandline)
« Reply #2 on: November 13, 2018, 04:12:36 PM »

Galapo

  • Gena Baker
  • Grand Chef
  • *****
  • Location: Australia
  • Date Registered: Sep 2010
  • Posts: 2207
You could use this code:

Code: [Select]
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <iostream>

void usage(const char *title)
{
printf("Usage: \n" \
" %s time-to-sleep-in-seconds\n",
title, title, title);
exit(1);
}

int main(int argc, char* argv[])
{
DWORD mSec = 1000;

if((argc < 2) || (0 == stricmp("/?", argv[1])) || (0 == stricmp("-h", argv[1])) || (0 == stricmp("/h", argv[1])))
{
usage(argv[0]);
}

for (int sec = atoi(argv[1]); sec >= 0; sec--)
{
Sleep(1000);
system("cls");
std::cout << "Sleeping for: " << sec << " seconds remaining";
}
system("cls");
return 0;
}

I'll have to track down where I saved my copy of Visual Studio to compile this one. Not happy with the Mingw size due to having to link a static file which boosts the size considerably.

Regards,
Galapo.

Re: Sleep (for pausing commandline)
« Reply #3 on: November 13, 2018, 08:51:57 PM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 10350
Well, you can create Sleep with AutoIT for home use where size is not important.  :wink:

This way current sleep stay small for projects, and home use can have more features and easier for you to maintain.

*
I need "sleep" with the countdown for home use,
 There may be alternatives on the internet but I prefer first using our tools that would help to develop better.

:turtle:

Re: Sleep (for pausing commandline)
« Reply #4 on: November 14, 2018, 05:22:27 PM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 10350
Hi Galapo,

I start using old version of Switch Off (2.3.0.1) for sleep and shutdown
ps:
Latest here http://www.airytec.com/en/switch-off/get.aspx but I like old gui design.

It is the utility I use since XP, only first time I start using it with cmd batch.

Latest version still looks cool and tidy.

:turtle:

Re: Sleep (for pausing commandline)
« Reply #5 on: November 15, 2018, 03:20:51 AM »

Galapo

  • Gena Baker
  • Grand Chef
  • *****
  • Location: Australia
  • Date Registered: Sep 2010
  • Posts: 2207
I dug up the external harddrive where I had Visual Studio installed in a virtual machine.

I've compiled a sleep.exe for you that outputs a countdown. Simply run 'sleep.exe 10' on the commandline to sleep for 10 seconds.

Regards,
Galapo.

Re: Sleep (for pausing commandline)
« Reply #6 on: November 15, 2018, 04:41:56 PM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 10350
Thanks Galapo.

It works nice.  :thumbsup:  :cheers:

:turtle:

Re: Sleep (for pausing commandline)
« Reply #7 on: November 16, 2018, 09:38:22 AM »

Galapo

  • Gena Baker
  • Grand Chef
  • *****
  • Location: Australia
  • Date Registered: Sep 2010
  • Posts: 2207
Great!  :grin:

Re: Sleep (for pausing commandline)
« Reply #8 on: November 18, 2018, 04:51:26 AM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 10350
Hi Galapo,

I just put a copy of sleep_Timer.rar to "Sleep.exe by Galapo" plugin to keep it at a safe place.  :great:
:turtle:

Re: Sleep (for pausing commandline)
« Reply #9 on: November 18, 2018, 06:14:41 AM »

Galapo

  • Gena Baker
  • Grand Chef
  • *****
  • Location: Australia
  • Date Registered: Sep 2010
  • Posts: 2207
 :thumbsup:

Re: Sleep (for pausing commandline)
« Reply #10 on: November 18, 2018, 01:29:16 PM »

sandy

  • Jr. Chef
  • **
  • Date Registered: Oct 2018
  • Posts: 49
If you stop using the c/c++ runtime you can get the x64 version under 7K and the x86 version under 6K:

// Sleep.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#define _WIN32_WINNT 0x0500

#include <windows.h>
#include <tchar.h>
#include <strsafe.h>

#define DebugOut DebugOutW

#ifndef _DEBUG
#pragma comment(linker, "/entry:EntryPoint")
#endif

static HANDLE stdoutput;

void OpenDebugHandle()
{
    stdoutput = GetStdHandle(STD_OUTPUT_HANDLE);
}

void DebugOutW(LPCWSTR format, ...)
{
    WCHAR buff[1024];
    CHAR buffc[1024];

    va_list args;

    va_start(args, format);

    int len = wvsprintfW(buff, format, args);
    len = WideCharToMultiByte(CP_ACP, 0, buff, len, buffc, 1024, NULL, NULL);
    WriteFile(stdoutput, buffc, len, NULL, NULL);
}

void usage(const TCHAR *title)
{
    DebugOut(_T("Usage: \n%s time-to-sleep-in-seconds\n"), title);
}

BOOL IsHelp(TCHAR * par)
{
    TCHAR ch = par[0];
    DWORD len = lstrlen(par);
    if (len != 2)
        return FALSE;

    if (ch != _T('/') && ch != _T('-'))
        return FALSE;

    ch = par[1];
    return ch == _T('?') || ch == _T('h') || ch == _T('H');
}

DWORD ToInt32(TCHAR * par)
{
    DWORD num = 0;
    for (; *par != 0; ++par)
    {
        TCHAR ch = *par;
        if (ch < _T('0') || ch > _T('9'))
            break;
        num = 10 * num;
        num += (ch - _T('0'));
    }
    return num;
}

int _tmain(int argc, TCHAR* argv[])
{
    OpenDebugHandle();

    DWORD mSec = 1000;

    if (argc < 2 || IsHelp(argv[1]))
    {
        usage(argv[0]);
        return 1;
    }

    for (int sec = ToInt32(argv[1]); sec >= 0; sec--)
    {
        Sleep(1000);
        DebugOut(_T("Sleeping for: %u seconds   \r"), sec);
    }
    DebugOut(_T("\r\n"));
    return 0;
}

void EntryPoint()
{
    LPWSTR *szWArglist;
    int nArgs;

    WCHAR * cmd = GetCommandLineW();
    szWArglist = CommandLineToArgvW(cmd, &nArgs);
    DWORD ret;

    ret = _tmain(nArgs, szWArglist);

    LocalFree(szWArglist);
    ExitProcess(ret);
}




Re: Sleep (for pausing commandline)
« Reply #11 on: November 18, 2018, 08:59:50 PM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 10350
« Last Edit: November 18, 2018, 09:02:55 PM by Lancelot »

Re: Sleep (for pausing commandline)
« Reply #12 on: November 19, 2018, 09:38:58 AM »

Galapo

  • Gena Baker
  • Grand Chef
  • *****
  • Location: Australia
  • Date Registered: Sep 2010
  • Posts: 2207
Hi Sandy,

Welcome and thanks for your input. :great:

What IDE should I use and how do I compile the code?

Thanks,
Galapo.

Re: Sleep (for pausing commandline)
« Reply #13 on: November 19, 2018, 04:42:41 PM »

slore

  • WimBuilder
  • Sr. Chef
  • ****
  • Date Registered: Jun 2016
  • Posts: 664
such a simple C code, just use Galapo Reply #2 on: November 13, 2018, 10:12:36 AM ยป 's source code,
complie with tinycc, got <3kb one(both x64/x86).

diff:
Code: [Select]
-#include <iostream>
+printf("Sleeping for:%d seconds remaining", sec);

also 1 year ago, I complie hiderun.exe with tcc in 4kb.
« Last Edit: November 19, 2018, 04:43:40 PM by slore »

Re: Sleep (for pausing commandline)
« Reply #14 on: November 20, 2018, 04:51:56 AM »

Galapo

  • Gena Baker
  • Grand Chef
  • *****
  • Location: Australia
  • Date Registered: Sep 2010
  • Posts: 2207
Thanks slore for the heads-up.  :thumbsup: I confess I haven't used TCC before - I'll check it out.

Regards,
Galapo.

Re: Sleep (for pausing commandline)
« Reply #15 on: November 20, 2018, 03:08:20 PM »

sandy

  • Jr. Chef
  • **
  • Date Registered: Oct 2018
  • Posts: 49
I compiled with VS2017 with unicode configured. Here is my vcxproj:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|Win32">
      <Configuration>Debug</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <VCProjectVersion>15.0</VCProjectVersion>
    <ProjectGuid>{AAD971E3-F50B-4A35-9324-9B3A66506478}</ProjectGuid>
    <Keyword>Win32Proj</Keyword>
    <RootNamespace>Sleep</RootNamespace>
    <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v141</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v141</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v141</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v141</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="Shared">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <PrecompiledHeader>NotUsing</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <PrecompiledHeader>NotUsing</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <PrecompiledHeader>NotUsing</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <PrecompiledHeader>NotUsing</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>MinSpace</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
      <FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup>
    <ClCompile Include="Sleep.cpp" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>

Re: Sleep (for pausing commandline)
« Reply #16 on: November 20, 2018, 03:09:35 PM »

sandy

  • Jr. Chef
  • **
  • Date Registered: Oct 2018
  • Posts: 49
Sleep.vcxproj.filters:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Filter Include="Source Files">
      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
    </Filter>
    <Filter Include="Header Files">
      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
      <Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
    </Filter>
    <Filter Include="Resource Files">
      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
    </Filter>
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="Sleep.cpp">
      <Filter>Source Files</Filter>
    </ClCompile>
  </ItemGroup>
</Project>

Re: Sleep (for pausing commandline)
« Reply #17 on: November 20, 2018, 03:11:57 PM »

sandy

  • Jr. Chef
  • **
  • Date Registered: Oct 2018
  • Posts: 49
Looks like the board software corrupts the xmlns link.

Re: Sleep (for pausing commandline)
« Reply #18 on: November 20, 2018, 10:27:40 PM »

James

  • Grand Chef
  • *****
  • Location: USA
  • Date Registered: Dec 2017
  • Posts: 2272
You should use The CodeBox

Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Filter Include="Source Files">
      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
    </Filter>
    <Filter Include="Header Files">
      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
      <Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
    </Filter>
    <Filter Include="Resource Files">
      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
    </Filter>
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="Sleep.cpp">
      <Filter>Source Files</Filter>
    </ClCompile>
  </ItemGroup>
</Project>
« Last Edit: November 20, 2018, 10:28:57 PM by James »

 

Powered by EzPortal