diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..082b194 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "makefile.configureOnOpen": false +} \ No newline at end of file diff --git a/README.md b/README.md index 4cb3e9a..ba8c3ba 100644 --- a/README.md +++ b/README.md @@ -21,4 +21,16 @@ wincmd # Передача команды через параметр wincmd --command КОМАНДА wincmd -c КОМАНДА +# Запуск скрипта +wincmd ИМЯ_СКРИПТА.bat +wincmd -c "call ИМЯ_СКРИПТА.bat" ``` +## Скрипты +Можно использовать для запуска файлов [**WIN_BATCH**](https://w.wiki/HgPq "Batch скрипты"). +Пример: +```bash +touch hello.bat +echo -e "@echo off\necho Hello, world!" > hello.bat +wincmd hello.bat +``` + diff --git a/hello.bat b/hello.bat new file mode 100644 index 0000000..e0764a2 --- /dev/null +++ b/hello.bat @@ -0,0 +1,2 @@ +@echo off +echo Hello, world! diff --git a/wincmd b/wincmd index 0b02205..154c991 100755 Binary files a/wincmd and b/wincmd differ diff --git a/wincmd.h b/wincmd.h index db5eed5..e4a3cb1 100644 --- a/wincmd.h +++ b/wincmd.h @@ -45,6 +45,7 @@ static void __help(void) { "Console wincmd on Wine API V" VERSION "\n" " " "Run Windows command on the Linux" "\n" "Using:" "\n" + " " "wincmd SCRIPT_NAME" "\n" " " "wincmd [--help/--version]" "\n" " " "wincmd --command WINDOWS_COMMAND" ); @@ -55,6 +56,7 @@ int _lib_wincmd_main(int argc, char** argv) { char command_buffer[BUFFER_SIZE] = "wine cmd.exe /C "; long add_count = BUFFER_SIZE - strlen(command_buffer) - 1; bool get_command = false; + char* file_name = NULL; while (pos != (size_t)argc) { char* str = argv[pos]; if (get_command == true) { @@ -75,7 +77,7 @@ int _lib_wincmd_main(int argc, char** argv) { switch (str[1 + loc]) { default: if (get_command == true) break; - wincmd_error("Cannot find option!"); + printf("\033[1mwincmd: \033[91mCannot find option \"%s\"!\033[0m\n", str); return EXIT_FAILURE; break; case 'c': @@ -89,8 +91,8 @@ int _lib_wincmd_main(int argc, char** argv) { return EXIT_SUCCESS; } } else { - wincmd_error("Cannot find option!"); - return EXIT_FAILURE; + file_name = str; + break; } pos ++; } @@ -99,6 +101,17 @@ int _lib_wincmd_main(int argc, char** argv) { wincmd_error("Unable to find critical dependencies for running the CMD.EXE shell!"); return EXIT_FAILURE; } + if (file_name != NULL) { + strcpy(command_buffer, "wine cmd.exe /C call "); + strncat(command_buffer, file_name, BUFFER_SIZE - 10); + command_buffer[BUFFER_SIZE - 1] = '\0'; + stat = system(command_buffer); + if (stat != EXIT_SUCCESS) { + printf("\033[1mwincmd: \033[91mThe program terminates with status %d!\033[0m\n", stat); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; + } if (get_command == true) { stat = system(command_buffer); if (stat != EXIT_SUCCESS) {