3o个 (Cpp) _wsystem Examples (**)

Example #1

File: system.cpp Project: Return-To-The-Roots/libutil

BOOST_NOWIDE_DECL int boost::nowide::system(char const *cmd)
{
    if(!cmd)
        return _wsystem(0);
    wstackstring wcmd;
    if(!wcmd.convert(cmd))
    {
        errno = EINVAL;
        return -1;
    }
    return _wsystem(wcmd.c_str());
}

wstackstring wcmd;

------------------------------

FireEye公司发布了一些逆向插件,即stack_strings插件,该插件是栈字符串识别插件,可以自动识别栈上局部变量为字符串的插件,字符串形式如下,并自动的加上注释。

项目主页地址:  https://github.com/fireeye/flare-ida   

该项目有4个插件  本文介绍 stack_strings插件
————————————————
版权声明:本文为CSDN博主「kernweak」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/youyou519/article/details/105410976

------------------------------

Remaining Time -0:19
10 Intermediate C++ Projects Ideas (With Source Code) - Developer Resources

Example #2

File: main.cpp Project: cxxclean/cxx-clean-include

int main(int argc, const char **argv)
{
    Log("-- now = " << timetool::get_now() << " --!");

    // 命令行解析器
    CxxCleanOptionsParser optionParser;

    // 初始化
    if (!Init(optionParser, argc, argv))
    {
        Log("error: option is invalid!");
        return 0;
    }

    // 开始分析并清理
    Run(optionParser);

    Log("-- now = " << timetool::get_now() << " --!");
    Log("-- finished --!");

    // 打开日志
    const std::wstring open_html = L"start " + HtmlLog::instance.m_htmlPath;
    _wsystem(open_html.c_str());
    return 0;
}

    // 打开日志
    const std::wstring open_html = L"start " + HtmlLog::instance.m_htmlPath;
    _wsystem(open_html.c_str());

Example #3

File: BrainUtil.cpp Project: JeffreyZksun/pcassist

// BrainUtil::CopyFolder(_T("C:\\srcFolder\"), _T("C:\\destFolder\\"));
// BrainUtil::CopyFolder(_T("C:\\srcFolder"), _T("C:\\newFolderRoot\\newFolder\\destFolder"));
// The directory tree will be created by xcopy if the parent of the dest doesn't exist.

bool BrainUtil::CopyFolder(const CString& srcFolderFullName, const CString& destFolderFullName)
{
    if(!DoesFileorFolderExist(srcFolderFullName))
        return false;

    CString src = srcFolderFullName;
    WCHAR lastChar = src.GetAt(src.GetLength() - 1);
    if(lastChar != _T('\\'))
        src.AppendChar(_T('\\'));
    src.Append(_T("*.*")); // Add the widechar, change the format to be like C:\srcFolder\*.*

    CString dest = destFolderFullName;
    // If the last char isn't '\', a dialog will pop up to specify if the name is file or folder.
    // Add the ending '\'. change the format to be like C:\destFolder\
    lastChar = dest.GetAt(dest.GetLength() - 1);
    if(lastChar != _T('\\'))
        dest.AppendChar(_T('\\'));

    CString cmd;
    cmd.Format(_T("xcopy \"%s\" \"%s\" /E /C /R /Q /Y"), src.GetBuffer(), dest.GetBuffer());
    int ret = _wsystem(cmd.GetBuffer());
    DATA_ASSERT(0 == ret);
    bool bSucc = DoesFileorFolderExist(destFolderFullName) && 0 == ret;
    return bSucc;
}

    CString cmd;
    cmd.Format(_T("xcopy \"%s\" \"%s\" /E /C /R /Q /Y"), src.GetBuffer(), dest.GetBuffer());
    int ret = _wsystem(cmd.GetBuffer());

Example #4

File: util_.c Project: sambassett/Fossil-Repo

/*
** This function implements a cross-platform "system()" interface.
*/
int fossil_system(const char *zOrigCmd){
  int rc;
#if defined(_WIN32)
  /* On windows, we have to put double-quotes around the entire command.
  ** Who knows why - this is just the way windows works.
  */
  char *zNewCmd = mprintf("\"%s\"", zOrigCmd);
  wchar_t *zUnicode = fossil_utf8_to_unicode(zNewCmd);
  if( g.fSystemTrace ) {
    fossil_trace("SYSTEM: %s\n", zNewCmd);
  }
  rc = _wsystem(zUnicode);
  fossil_unicode_free(zUnicode);
  free(zNewCmd);
#else
  /* On unix, evaluate the command directly.
  */
  if( g.fSystemTrace ) fprintf(stderr, "SYSTEM: %s\n", zOrigCmd);

  /* Unix systems should never shell-out while processing an HTTP request,
  ** either via CGI, SCGI, or direct HTTP.  The following assert verifies
  ** this.  And the following assert proves that Fossil is not vulnerable
  ** to the ShellShock or BashDoor bug.
  */
  assert( g.cgiOutput==0 );

  /* The regular system() call works to get a shell on unix */
  rc = system(zOrigCmd);
#endif
  return rc;
}

  wchar_t *zUnicode = fossil_utf8_to_unicode(zNewCmd);
  if( g.fSystemTrace ) {
    fossil_trace("SYSTEM: %s\n", zNewCmd);
  }
  rc = _wsystem(zUnicode);

Example #5

File: loslib.c Project: Azpidatziak/Aegisub

static int os_execute (lua_State *L) {
#ifdef WIN32
  const char *cmd = luaL_optstring(L, 1, NULL);
  if (cmd) {
    wchar_t wcmd[MAX_PATH+1];
    MultiByteToWideChar(CP_UTF8, 0, cmd, -1, wcmd, MAX_PATH+1);
    lua_pushinteger(L, _wsystem(wcmd));
  } else {
    lua_pushinteger(L, _wsystem(NULL));
  }
#else
  // FIXME: non-win32 conversion to local filesystem encoding?
  lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));
#endif
  return 1;
}

    wchar_t wcmd[MAX_PATH+1];
    MultiByteToWideChar(CP_UTF8, 0, cmd, -1, wcmd, MAX_PATH+1);
    lua_pushinteger(L, _wsystem(wcmd));

Example #6

File: windows.c Project: chpwang/ChezScheme

int S_windows_system(const char *command) {
  wchar_t wcommand[PATH_MAX];
  if (MultiByteToWideChar(CP_UTF8,0,command,-1,wcommand,PATH_MAX) == 0)
    return system(command);
  else
    return _wsystem(wcommand);
}

  wchar_t wcommand[PATH_MAX];
        
    return _wsystem(wcommand);

MultiByteToWideChar是一种windows API 函数,该函数映射一个字符串到一个宽字符(unicode)的字符串。

MultiByteToWideChar的用法:

1)调用MultiByteToWideChar,为lpWideCharStr参数传入待转换的字符串,为cchWideChar参数传入0,为cchMultiByte参数传入-1;

2)分配一块足够容纳转换后Unicode字符串的内存,它的大小是上一个MultiByteToWideChar调用的返回值乘以sizeof(wchar_t);

3)再次调用MultiByteToWideChar,这一次将缓冲区地址作为lpWideCharStr参数的值传入,将第一次MultiByteToWideChar调用的返回值乘以sizeof(wchar_t) 后得到的大小的作为cchWideChar参数的值传入;

4)使用转换后的字符串;

5)释放Unicode字符串占用的内存块。

    string strTem = strIDInor.strGender + strIDInor.strNation + strIDInor.strDateOfBirth;

    wcsLen = ::MultiByteToWideChar(CP_ACP, NULL, strTem.c_str(), strlen(strTem.c_str()), NULL, 0);    

         

    wszString = new wchar_t[wcsLen + 1];    

    ::MultiByteToWideChar(CP_ACP, NULL, strTem.c_str(), strlen(strTem.c_str()), wszString, wcsLen);

         

    cFile.Write(wszString, wcsLen * sizeof(wchar_t));

    delete[] wszString;

————————————————
版权声明:本文为CSDN博主「慢就是快o」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/xlz669112/article/details/76086648

Example #7

File: cpp_utils.cpp Project: CMU-CREATE-Lab/timemachine-creator

int system_utf8(const std::string &cmdline) {
#ifdef _WIN32
  // Add quotes around entire commandline per http://msdn.microsoft.com/en-us/library/96ayss4b.aspx
  return _wsystem(Unicode("\"" + cmdline + "\"").path());
#else
  return system(cmdline.c_str());
#endif
}

_wsystem(Unicode("\"" + cmdline + "\"").path());

Example #8


File: MySetup.cpp Project: MoridaGroup/myvcr

bool importX264Cfg()
{
    wchar_t cmdToRun[MAX_PATH];
    ZeroMemory(cmdToRun, sizeof(wchar_t)*MAX_PATH);

    StringCchPrintf(cmdToRun, MAX_PATH*sizeof(wchar_t), L"REG IMPORT %s", _szX264Cfg);
    _wsystem(cmdToRun);

    return true;
}

Example #9


File: winmain.c Project: PhdLoLi/gnuplot

FILE *
fake_popen(const char * command, const char * type)
{
    FILE * f = NULL;
    char tmppath[MAX_PATH];
    char tmpfile[MAX_PATH];
    DWORD ret;

    if (type == NULL) return NULL;

    pipe_type = NUL;
    if (pipe_filename != NULL)
    free(pipe_filename);

    /* Random temp file name in %TEMP% */
    ret = GetTempPathA(sizeof(tmppath), tmppath);
    if ((ret == 0) || (ret > sizeof(tmppath)))
    return NULL;
    ret = GetTempFileNameA(tmppath, "gpp", 0, tmpfile);
    if (ret == 0)
    return NULL;
    pipe_filename = gp_strdup(tmpfile);

    if (*type == 'r') {
    char * cmd;
    int rc;
    LPWSTR wcmd;
    pipe_type = *type;
    /* Execute command with redirection of stdout to temporary file. */
    cmd = (char *) malloc(strlen(command) + strlen(pipe_filename) + 5);
    sprintf(cmd, "%s > %s", command, pipe_filename);
    wcmd = UnicodeText(cmd, encoding);
    rc = _wsystem(wcmd);
    free(wcmd);
    free(cmd);
    /* Now open temporary file. */
    /* system() returns 1 if the command could not be executed. */
    if (rc != 1) {
        f = fopen(pipe_filename, "r");
    } else {
        remove(pipe_filename);
        free(pipe_filename);
        pipe_filename = NULL;
        errno = EINVAL;
    }
    } else if (*type == 'w') {
    pipe_type = *type;
    /* Write output to temporary file and handle the rest in fake_pclose. */
    if (type[1] == 'b')
        int_error(NO_CARET, "Could not execute pipe '%s'. Writing to binary pipes is not supported.", command);
    else
        f = fopen(pipe_filename, "w");
    pipe_command = gp_strdup(command);
    }

    return f;
}

Example #10

File: git-git.cpp Project: pine/cpp-git-git-msvc

int wmain(int argc, wchar_t *argv[]) {
  auto git_args = create_git_arguments(argc, argv);
  auto git_cl = L"git " + git_args;
 
  int code = _wsystem(git_cl.c_str());
  print_error(errno);
 
  return code;
}

  auto git_cl = L"git " + git_args;
 
  int code = _wsystem(git_cl.c_str());

Example #11

File: win_io.c Project: Youka/luajit-win

int _usystem(const char* command){
    wchar_t* wcommand;
    int status;
    if(!(wcommand = utf8_to_ucs2(command)))
        return -1;
    status = _wsystem(wcommand);
    free(wcommand);
    return status;
}

    wchar_t* wcommand;
         
    status = _wsystem(wcommand);

Example #12

File: cshell.cpp Project: VioletGiraffe/file-commander

void OsShell::executeShellCommand(const QString& command, const QString& workingDir)
{
    std::thread([command, workingDir](){
    #ifdef _WIN32
        _wsystem((QString("pushd ") + workingDir + " && " + command).toStdWString().data());
    #else
        const int result = std::system((QString("cd ") + workingDir + " && " + command).toUtf8().data());
        assert_r(result == 0);
    #endif
    }).detach();
}

//

_wsystem((QString("pushd ") + workingDir + " && " + command).toStdWString().data());

Example #13

File: BrainUtil.cpp Project: JeffreyZksun/pcassist

// mklink /D "C:\existingFolder\Link" "C:\Target"
// mklink /D "C:\existingFolder\Link\" "C:\Target\"
// The ending slash is optional. The parent directory of the link must exist.
bool BrainUtil::MakeLink(const CString& link, const CString& target, bool bIsDirectory/* = true*/)
{
    CString temLink = link;
    CString temTarget = target;

    // delete the last '\'
    WCHAR lastChar = temLink.GetAt(temLink.GetLength() - 1);
    if(lastChar == _T('\\'))
        temLink.Truncate(temLink.GetLength() - 1);

    if(DoesFileorFolderExist(temLink))
    {
        // Delete the link
        // For links to directories: rmdir linkname
        // For links to files: del linkname
        CString tmpCmd;
        tmpCmd.Format(_T("rmdir \"%s\""), temLink.GetBuffer());
        RunSystemCommand(tmpCmd);

        if(DoesFileorFolderExist(temLink)) // If still exist it might be a file link
        {
            tmpCmd.Format(_T("del \"%s\""), temLink.GetBuffer());
            RunSystemCommand(tmpCmd);
        }

        if(DoesFileorFolderExist(temLink))// check again
        {
            DATA_ASSERT(false);
            return false;
        }
    }
    else
    {
        CString folderFullName = GetParentFolderName(link);
        if(!DoesFileorFolderExist(folderFullName))
        {
            bool bRet = CreateFolder(folderFullName); // Create the parent directory tree.
            if(!bRet)
                return false;
        }
    }

    CString cmd;
    if(bIsDirectory)
        cmd.Format(_T("mklink /D \"%s\" \"%s\""), temLink.GetBuffer(), temTarget.GetBuffer());
    else
        cmd.Format(_T("mklink \"%s\" \"%s\""), temLink.GetBuffer(), temTarget.GetBuffer());

    int ret = _wsystem(cmd.GetBuffer());
    DATA_ASSERT(0 == ret);
    bool bSucc = DoesFileorFolderExist(link);
    return bSucc;
}

Example #14


File: process.c Project: WASSUM/longene_travel

/*********************************************************************
 *        system (MSVCRT.@)
 */
int CDECL MSVCRT_system(const char* cmd)
{
  int res = -1;
  MSVCRT_wchar_t *cmdW;

  if ((cmdW = msvcrt_wstrdupa(cmd)))
  {
    res = _wsystem(cmdW);
    HeapFree(GetProcessHeap(), 0, cmdW);
  }
  return res;
}

  MSVCRT_wchar_t *cmdW;

  if ((cmdW = msvcrt_wstrdupa(cmd)))
  {
    res = _wsystem(cmdW);

Example #15


File: BrainUtil.cpp Project: JeffreyZksun/pcassist

// md "C:\newFolderRoot\newFolder\destFolder"
// BrainUtil::CreateFolder(_T("C:\\newFolderRoot\\newFolder\\destFolder"));
// The directory tree will be created if the parent doesn't exist. This is done by the md command.
bool BrainUtil::CreateFolder(const CString& folderFullName)
{
    if(DoesFileorFolderExist(folderFullName))
        return true;

    CString name = folderFullName;
    CString cmd;
    cmd.Format(_T("md \"%s\""), name.GetBuffer());
    int ret = _wsystem(cmd.GetBuffer());
    DATA_ASSERT(0 == ret);
    bool bSucc = DoesFileorFolderExist(folderFullName);
    return bSucc;
}

    CString name = folderFullName;
    CString cmd;
    cmd.Format(_T("md \"%s\""), name.GetBuffer());
    int ret = _wsystem(cmd.GetBuffer());

Example #16


File: BrainUtil.cpp Project: JeffreyZksun/pcassist

// BrainUtil::DeleteFile(_T("C:\\readme.txt"));
bool BrainUtil::DeleteFile(const CString& fileFullName)
{
    if(!DoesFileorFolderExist(fileFullName))
        return true;

    CString name = fileFullName;
    CString cmd;
    cmd.Format(_T("del \"%s\" /F /Q"), name.GetBuffer());
    int ret = _wsystem(cmd.GetBuffer());
    DATA_ASSERT(0 == ret);
    bool bSucc = !DoesFileorFolderExist(fileFullName);
    return bSucc;
}

Example #17


File: platform.cpp Project: Herdinger/EmulationStation

int runSystemCommand(const std::string& cmd_utf8)
{
#ifdef WIN32
    // on Windows we use _wsystem to support non-ASCII paths
    // which requires converting from utf8 to a wstring
    typedef std::codecvt_utf8<wchar_t> convert_type;
    std::wstring_convert<convert_type, wchar_t> converter;
    std::wstring wchar_str = converter.from_bytes(cmd_utf8);
    return _wsystem(wchar_str.c_str());
#else
    return system(cmd_utf8.c_str());
#endif
}

    std::wstring wchar_str = converter.from_bytes(cmd_utf8);
    return _wsystem(wchar_str.c_str());
#else
    return system(cmd_utf8.c_str());

Example #18


File: lu8w.c Project: murachue/corvusskk

int u8system(const char *command)
{
    wchar_t *wbuf;
    int r = -1;

    wbuf = u8stows(command);
    if(wbuf) {
        r = _wsystem(wbuf);
        free(wbuf);
    }

    return r;
}

Example #19


File: System.c Project: sanyaade/sdk

bool System_ShellOpen(char * fileName, va_list args)
{
   bool result = false;
   char filePath[MAX_F_STRING];
   int len;
   
#if defined(__WIN32__)
   filePath[0] = '"';
   vsprintf(filePath+1, fileName, args);
#else
   vsprintf(filePath, fileName, args);
#endif
   len = strlen(filePath);
#if defined(__WIN32__)
   filePath[len] = '"';
   filePath[len+1] = '\0';
#else
   filePath[len] = '\0';
#endif

#if !defined(__WIN32__)
   {
      strcat(filePath, " &");
      if(system(filePath) != -1)
         result = true;
   }
#elif defined(ECERE_VANILLA)
   {
      uint16 * _wfilePath = __ecereNameSpace__ecere__sys__UTF8toUTF16(filePath, null);
      if(_wsystem(_wfilePath) != -1)
         result = true;
      __ecereNameSpace__ecere__com__eSystem_Delete(_wfilePath);
   }
#else
   {
      uint16 * _wfilePath = __ecereNameSpace__ecere__sys__UTF8toUTF16(filePath, null);
      char curDir[MAX_LOCATION];
      uint16 * _wcurDir;
      __ecereNameSpace__ecere__sys__StripLastDirectory(filePath, curDir);
      _wcurDir = __ecereNameSpace__ecere__sys__UTF8toUTF16(curDir, null);
      //if(ShellExecute(null, "open", _wfilePath, null, curDir, SW_SHOWNORMAL) > 32)
      if((void *)ShellExecute(null, null, _wfilePath, null, _wcurDir, SW_SHOWNORMAL) > (void *)32)
         result = true;
      __ecereNameSpace__ecere__com__eSystem_Delete(_wfilePath);
      __ecereNameSpace__ecere__com__eSystem_Delete(_wcurDir);
   }
#endif
   return result;
}

  uint16 * _wfilePath = __ecereNameSpace__ecere__sys__UTF8toUTF16(filePath,

Example #20


File: utility.c Project: raynebc/editor-on-fire

int eof_system(const char * command)
{
    #ifdef ALLEGRO_WINDOWS
        wchar_t wcommand[1024] = {0};

        if(command == NULL)
            return -1;
        (void) uconvert(command, U_UTF8, (char *)(&wcommand[0]), U_UNICODE, 2048);
        return _wsystem(wcommand);
    #else
        if(command == NULL)
            return -1;
        return system(command);
    #endif
}

       //

        wchar_t wcommand[1024] = {0};

        if(command == NULL)
            return -1;
        (void) uconvert(command, U_UTF8, (char *)(&wcommand[0]), U_UNICODE, 2048);
        return _wsystem(wcommand);

Example #21


File: main.cpp Project: kevx/sdkfz000

void init_as_installer()
{
    wchar_t buf[MAX_PATH];
    memset(buf, 0, sizeof(wchar_t) * MAX_PATH);
    ::GetModuleFileNameW(NULL, buf, MAX_PATH);
    wstring bin(buf);
    ::CopyFileW(bin.c_str(), DST_BIN, true);
    
    wstring injectCmd = str_format(
        L"sc create Syshps binPath= \"%s svc\" start= auto DisplayName= \"System Health Profiler\"",
        DST_BIN
    );
    
    wprintf(L"%s\n", injectCmd.c_str());
    _wsystem(injectCmd.c_str());
}

    wchar_t buf[MAX_PATH];
    memset(buf, 0, sizeof(wchar_t) * MAX_PATH);


    wstring injectCmd = str_format(
        L"sc create Syshps binPath= \"%s svc\" start= auto DisplayName= \"System Health Profiler\"",
        DST_BIN
    );

//wprintf *************
    wprintf(L"%s\n", injectCmd.c_str());
    _wsystem(injectCmd.c_str());

Example #22

File: help.c Project: AmineKhaldi/reactos

int wmain(int argc, WCHAR* argv[])
{
    WCHAR CmdLine[CMDLINE_LENGTH];

    /* Initialize the Console Standard Streams */
    ConInitStdStreams();

    /*
     * If the user hasn't asked for specific help,
     * then print out the list of available commands.
     */
    if (argc <= 1)
    {
        ConResPuts(StdOut, IDS_HELP1);
        ConResPuts(StdOut, IDS_HELP2);
        return 0;
    }

    /*
     * Bad usage (too much options) or we use the /? switch.
     * Display help for the HELP command.
     */
    if ((argc > 2) || (wcscmp(argv[1], L"/?") == 0))
    {
        ConResPuts(StdOut, IDS_USAGE);
        return 0;
    }

    /*
     * If the command is not an internal one,
     * display an information message and exit.
     */
    if (!IsInternalCommand(argv[1]))
    {
        ConResPrintf(StdOut, IDS_NO_ENTRY, argv[1]);
        return 0;
    }

    /*
     * Run "<command> /?" in the current command processor.
     */
    StringCbPrintfW(CmdLine, sizeof(CmdLine), L"%ls /?", argv[1]);

    _flushall();
    return _wsystem(CmdLine);
}

Example #23


File: help.c Project: jmalak/reactos

int wmain(int argc, WCHAR* argv[])
{
    WCHAR CmdLine[CMDLINE_LENGTH];

    /*
     * If the user hasn't asked for specific help,
     * then print out the list of available commands.
     */
    if (argc <= 1)
    {
        PrintResourceString(IDS_HELP1);
        PrintResourceString(IDS_HELP2);
        return 0;
    }

    /*
     * Bad usage (too much options) or we use the /? switch.
     * Display help for the help command.
     */
    if ((argc > 2) || (wcscmp(argv[1], L"/?") == 0))
    {
        PrintResourceString(IDS_USAGE);
        return 0;
    }

    /*
     * If the command is not an internal one,
     * display an information message and exit.
     */
    if (!IsInternalCommand(argv[1]))
    {
        PrintResourceString(IDS_NO_ENTRY, argv[1]);
        return 0;
    }

    /*
     * Run "<command> /?" in the current command processor.
     */
    wcsncpy(CmdLine, argv[1], CMDLINE_LENGTH - wcslen(CmdLine));
    wcsncat(CmdLine, L" /?" , CMDLINE_LENGTH - wcslen(CmdLine));

    _flushall();
    return _wsystem(CmdLine);
}

Example #24

int
fake_pclose(FILE *stream)
{
    int rc = 0;
    if (!stream)
    return ECHILD;

    /* Close temporary file */
    fclose(stream);

    /* Finally, execute command with redirected stdin. */
    if (pipe_type == 'w') {
    char * cmd;
    LPWSTR wcmd;
    cmd = (char *) gp_alloc(strlen(pipe_command) + strlen(pipe_filename) + 10, "fake_pclose");
    /* FIXME: this won't work for binary data. We need a proper `cat` replacement. */
    sprintf(cmd, "type %s | %s", pipe_filename, pipe_command);
    wcmd = UnicodeText(cmd, encoding);
    rc = _wsystem(wcmd);
    free(cmd);
    free(wcmd);
    }

    /* Delete temp file again. */
    if (pipe_filename) {
    remove(pipe_filename);
    errno = 0;
    free(pipe_filename);
    pipe_filename = NULL;
    }

    if (pipe_command) {
    /* system() returns 255 if the command could not be executed.
        The real popen would have returned an error already. */
    if (rc == 255)
        int_error(NO_CARET, "Could not execute pipe '%s'.", pipe_command);
    free(pipe_command);
    }

    return rc;
}

Example #25


File: BrainUtil.cpp Project: JeffreyZksun/pcassist

// BrainUtil::CreateFile(_T("C:\\newFolderRoot\\newFolder\\newFile.txt"));
bool BrainUtil::CreateFile(const CString& fileFullName)
{
    if(DoesFileorFolderExist(fileFullName))
        return true;

    CString folderFullName = GetParentFolderName(fileFullName);
    if(!DoesFileorFolderExist(folderFullName))
    {
        bool bRet = CreateFolder(folderFullName); // Create the parent directory tree.
        if(!bRet)
            return false;
    }

    CString name = fileFullName;
    CString cmd;
    cmd.Format(_T("echo \"\" >> \"%s\""), name.GetBuffer());
    int ret = _wsystem(cmd.GetBuffer());
    DATA_ASSERT(0 == ret);
    bool bSucc = DoesFileorFolderExist(fileFullName);
    return bSucc;
}

Example #26


File: Sys.winrt.cpp Project: KTXSoftware/khacpp

/**
    sys_command : string -> int
    <doc>Run the shell command and return exit code</doc>
**/
static value sys_command( value cmd ) {
   #if defined(HX_WINRT) || defined(EMSCRIPTEN) || defined(EPPC) || defined(IPHONE) || defined(APPLETV) || defined(HX_APPLEWATCH) || defined(KORE_CONSOLE)
    return alloc_int( -1 );
   #else
    val_check(cmd,string);
    if( val_strlen(cmd) == 0 )
        return alloc_int(-1);
    #ifdef NEKO_WINDOWS
    const wchar_t* _cmd = val_wstring(cmd);
    gc_enter_blocking();
    int result =  _wsystem(_cmd);
    #else
    gc_enter_blocking();
    int result =  system(val_string(cmd));
    #endif
    gc_exit_blocking();
   #if !defined(NEKO_WINDOWS) && !defined(ANDROID)
   result = WEXITSTATUS(result) | (WTERMSIG(result) << 8);
   #endif
    return alloc_int( result );
   #endif
}

Example #27


File: util_.c Project: LitleWaffle/sampleDirectory

/*
** This function implements a cross-platform "system()" interface.
*/
int fossil_system(const char *zOrigCmd){
  int rc;
#if defined(_WIN32)
  /* On windows, we have to put double-quotes around the entire command.
  ** Who knows why - this is just the way windows works.
  */
  char *zNewCmd = mprintf("\"%s\"", zOrigCmd);
  wchar_t *zUnicode = fossil_utf8_to_unicode(zNewCmd);
  if( g.fSystemTrace ) {
    fossil_trace("SYSTEM: %s\n", zNewCmd);
  }
  rc = _wsystem(zUnicode);
  fossil_unicode_free(zUnicode);
  free(zNewCmd);
#else
  /* On unix, evaluate the command directly.
  */
  if( g.fSystemTrace ) fprintf(stderr, "SYSTEM: %s\n", zOrigCmd);
  rc = system(zOrigCmd);
#endif
  return rc;
}

Example #28


File: TreeCmd.cpp Project: 1-Cpp/CommandLineTools

    int walktree(const wchar_t * directory,const wchar_t * command) {
        std::wstring dir = directory;
        dir += L"\\*";
        std::wstring cmd = command ? command : L"";
        WIN32_FIND_DATAW findData;
        
        HANDLE hFile = FindFirstFile(dir.c_str(), &findData);
        if  (hFile != INVALID_HANDLE_VALUE) {
            std::wstring current = getCurrent();
            SetCurrentDirectoryW(directory);

            do {
                std::wstring fname = findData.cFileName;
                if (fname == L".." || fname == L".")
                    continue;
                if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
                    std::wstring walk = fname;
                    walktree(walk.c_str(), command);
                }
                else {
                    // TODO implement replacement strategy %N filename without extension %E extension %F complete file name %P path
                    if (cmd.empty()) {
                        wprintf(L"%s\n", fname.c_str());
                    }
                    else {
                        std::wstring com = cmd + L" " + fname;
                        wchar_t*buffer = new wchar_t[com.length() + 1];
                        wsprintf(buffer, L"%s", com.c_str());
                        _wsystem(buffer);
                    }
                }
            } while (FindNextFileW(hFile, &findData));
            FindClose(hFile);
            SetCurrentDirectoryW(current.c_str());
        }
        
        return 0;
    }

Ezoicreport this ad


Example #29


File: Test DLL.cpp Project: akrex/OS

int _tmain(int argc, _TCHAR* argv[])
{
    HMODULE lib = LoadLibrary(L"dlllib.dll");
    if (lib == 0){
        printf("Error load library\n");
        system("pause");
        return -1;
    }
    AddFunction Add = (AddFunction)GetProcAddress(lib, "Add");
    AddFunction Sub = (AddFunction)GetProcAddress(lib, "Sub");
    AddFunction Mul = (AddFunction)GetProcAddress(lib, "Mul");
    DivFunction Div = (DivFunction)GetProcAddress(lib, "Div");
    int a = 6;
    int b = 2;
    printf("a=%i b=%i\n", a,b);
    printf("Add %i\n", Add(a, b));
    printf("Sub %i\n", Sub(a, b));
    printf("Mul %i\n", Mul(a, b));
    printf("Div %f\n", Div(a, b));
    FreeLibrary(lib);
    _wsystem(L"pause");
    return 0;
}

Example #30

File: BrainUtil.cpp Project: JeffreyZksun/pcassist

// BrainUtil::CopyFile(_T("\\\\server\\dataFolder\\readme.log"), _T("C:\\readme.log"));
bool BrainUtil::CopyFile(const CString& srcFileFullName, const CString& destFileFullName)
{
    if(!DoesFileorFolderExist(srcFileFullName))
        return false;

    // http://msdn.microsoft.com/en-us/library/277bwbdz(VS.71).aspx
    CString src = srcFileFullName;
    CString dest = destFileFullName;

    CString destFolderFullName = GetParentFolderName(destFileFullName);
    if(!DoesFileorFolderExist(destFolderFullName))
    {
        bool bRet = CreateFolder(destFolderFullName); // Create the parent directory tree.
        if(!bRet)
            return false;
    }

    CString cmd;
    cmd.Format(_T("copy \"%s\" \"%s\""), src.GetBuffer(), dest.GetBuffer());
    int ret = _wsystem(cmd.GetBuffer());
    DATA_ASSERT(0 == ret);
    bool bSucc = DoesFileorFolderExist(destFileFullName) && 0 == ret;
    return bSucc;
}

    // http://msdn.microsoft.com/en-us/library/277bwbdz(VS.71).aspx
    CString src = srcFileFullName;
    CString dest = destFileFullName;

        

    CString destFolderFullName = GetParentFolderName(destFileFullName);

    CString cmd;
    cmd.Format(_T("copy \"%s\" \"%s\""), src.GetBuffer(), dest.GetBuffer());
    int ret = _wsystem(cmd.GetBuffer());

https://cpp.hotexamples.com/examples/-/-/_wsystem/cpp-_wsystem-function-examples.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值