File: winpath.cpp

package info (click to toggle)
tesseract 5.5.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 43,508 kB
  • sloc: cpp: 154,570; makefile: 1,519; java: 1,143; ansic: 852; sh: 763; python: 51
file content (39 lines) | stat: -rw-r--r-- 860 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (C) 2024 Stefan Weil
//
// SPDX-License-Identifier: Apache-2.0
//
// winpath - run a Windows program with extended PATH
//
// Usage:
//
//     winpath [CMD [ARGUMENT ...]]
//
// Example:
//
//     winpath cmd
//
// This will start a Windows command line with PATH extended by
// the location of the winpath executable.

#include <process.h>    // _spawnvp
#include <stdlib.h>     // _putenv_s
#include <string.h>     // strcpy, strcat

static char path[4096];

int main(int argc, char *argv[]) {
  if (argc > 1) {
    char *dir = argv[0];
    char *last = strrchr(dir, '\\');
    if (last != nullptr) {
      *last = '\0';
    }
    strcpy(path, dir);
    strcat(path, ";");
    strcat(path, getenv("PATH"));
    _putenv_s("PATH", path);
    _spawnvp(_P_WAIT, argv[1], argv + 1);
    //~ _spawnvp(_P_OVERLAY, argv[1], argv + 1);
  }
  return 0;
}