Html запуск командной строки из

Как запустить cmd.exe с параметрами из javascript

Я пытаюсь написать javascript, который должен запускать cmd.exe с указанной командной строкой, например, docs.google.com/file/d/0B7QHCoQDlEvKWUZSX3oxUDI2SDg/edit:

Я готовлю код после прочтения метода shellexecute на сайте Microsoft:

var objShell = new ActiveXObject("Shell.Application"); objShell.ShellExecute("cmd.exe", "C: cd C:\\pr main.exe blablafile.txt auto", "C:\\WINDOWS\\system32", "open", "1"); 

Но он не вставляет командную строку в cmd.exe.

Кто-нибудь может мне помочь? Заранее спасибо.

2 ответа

Возможно, на вашем компьютере этот элемент ActiveX не установлен (или не зарегистрирован).

WScript.Shell можно найти в каждой Windows:

var run=new ActiveXObject('WSCRIPT.Shell').Run("commands to run"); 

Если в commands to run есть пробелы, вам нужно использовать двойные кавычки.

iRetVal = Shell.ShellExecute( sFile, [ vArguments ], [ vDirectory ], [ vOperation ], [ vShow ] ) 

Возьмем [vDirectory] . В документации говорится: «Полный path of the directory , содержащий файл, указанный sFile. Если этот параметр не указан, используется текущий рабочий каталог».

Это означает, что у вас есть недопустимый путь для этого аргумента (с .cmd.exe в конце). Также все примеры создания ActiveX выглядят так:

var objShell = new ActiveXObject("shell.application"); 

Обратите внимание на строчные буквы в «shell.application» .

И 12 мая, спасибо, что спросили об этом. Раньше я не знал об этом элементе управления ActiveX, он мне кажется очень полезным.

РЕДАКТИРОВАТЬ II

Но вы это поняли? Ваш пример отлично работает в моем приложении:

objShell.ShellExecute("cmd.exe", "cd C: C:\\cd c:\\ext_file main.exe test.txt", "C:\\WINDOWS\\system32", "open", 1); 

1) Тот, который я упомянул ранее в этом ответе о пути

2) Экранированный \ также используется в аргументах.

3) Последний аргумент — это тип числа, а не строки.

var objShell = new ActiveXObject("Shell.Application"); objShell.ShellExecute("cmd.exe", "C: cd C:\\pr main.exe blablafile.txt auto", "C:\\WINDOWS\\system32", "open", "1"); 

Источник

Запуск командной строки с html-страницы

Запуск командной строки, через ярлык и с установкой кодовой страницы
Как можно установить в параметрах запуска, тип кодовой страницы У меня по умолчанию командная.

Запуск С Командной Строки
с виндяткой ситуация достаточно обсосана с линухами — все печальней (в смысле адекватной инфы от.

Запуск программы из командной строки
Здравствуйте. Подскажите, как запустить следующею программу из командной строки? #include.

Запуск из под командной строки
Здравствуйте!! Всех Вас с наступающим!! Есть надобность запустить mp3 файл на удаленных машинах.

Наверное никак, антивирусы будут на такое ругаться и блокировать.
Если ты хочешь сделать что-то вроде autorun’а и запускать из него что-то, то есть куча программ для компиляции HTML в exe (AppJS, Node-webkit).

Эксперт .NET

Написать программу для ПК, которая будет принимать запросы по сети от скрипта на web-странице.

Добавлено через 1 минуту

input type="button" value="Launch Installer" onclick="window.open('file:///S:/Test/Test.bat')" />
var commandtoRun = "C:\\Documents and Settings\\User\Desktop\\ABCD.exe"; var oShell = new ActiveXObject("Shell.Application"); var commandtoRun = "C:\\Windows\\notepad.exe"; oShell.ShellExecute(commandtoRun,"","","open","1");

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

HTML5 Command Line Terminal

License

mrchimp/cmd

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

HTML5 Command Line Terminal

Cmd turns a div into a kind of command line. It is designed to take a string input and return a plain text or HTML response by processing the input using Javascript or by using a remote server via a JSON API. It is designed to be extended and as such only provides a few basic commands (see below).

  • Tab completion for command names and parameters
  • JSON API
  • Text-to-speech output (optional, where available)

You can get Cmd with bower.

For more examples see example.html .

Required. (string: ‘#cmd’) Selector for div to use as terminal.

(string: ‘Communicating. ‘) Text to display when input is disabled during external processor requests.

To add extra commands to Cmd, pass a callback function in the options. This function should either return a response object (see below) or undefined .

If input is undefined , the command line will remain disabled until `handleResponse()« is called.

The value that external_processor returns defines how Cmd reacts:

  • true — Cmd will remain deactivated until your external script calls handleResponse .
  • false — unknown_cmd will be printed to screen.
  • object — Will be interpreted as a Cmd response object. See below for definition.
  • string — Will be output to screen.
  • Anything else — unknown_cmd will be printed to screen.

(boolean: false) If true , the terminal will allow files to be dropped on it and will post them to file_upload_url .

(string: ‘uploadfile.php’) Used when filedrop_enabled is true . A URL to post to when files are dropped on the terminal.

(string: ‘cmd_history’) Command history is stored in Local Storage. Use different ids if using multiple terminals on a page. Or don’t and they’ll share history. It’s up to you.

(string: ») A URL that provides a JSON representation of available remote commands that is used for command name tabcomplete. This is called once at boot time.

(string: ») A URL that provides parameter tabcompletion result when the input is more than one word.

(boolean: false) Enable talk mode by default.

(string: 32) Time between typewriter output keypresses.

(string: 200) Output length longer than this will not use the typewriter effect.

(string: ‘Unrecognised command’) String to respond with when unable to process a command.

The response object that is passed to handleResponse can have the following parameters.

  • cmd_in — required The input provided by the user.
  • cmd_out — required The response string.
  • redirect — URL to redirect browser to.
  • openWindow — URL to open in a new window.
  • log — String to output with console.log() .
  • hide_output — Mask cmd_in as asterisks when outputting.
  • show_pass — Switch to password input.
  • cmd_fill — String to insert into input.

Params: (string msg) — Append msg to the output.

Same as calling the clear command. Removes all output. Clears the screen. How else can I put it.

Params: (object response) — Called by external_processor to output a response. See above for response specification.

Toggle between light-on-dark and dar-on-light styles.

Params: (string new_prompt) — Change the prompt string.

Params: (string input_type) — Changes the type of input used. input_type should be ‘password’ (masks input as asterisks), ‘textarea’ (for large format text) or ‘normal’ (single line input). (If input_type is not set, ‘normal’ will be used).

Clear the screan. Same as clear on Unix or cls on Windows.

The command history that is accessed with the up arrow is stored in the browser’s local storage. clearhistory empties this list.

Toggle between light-on-dark and dark-and-light styles.

Toggle talk mode. When talk mode is enabled, responses will be read aloud.

«Panic button» that silences current speech and empties the talk queue. Talk mode remains enabled.

About

HTML5 Command Line Terminal

Источник

Html запуск командной строки из

Gray Pipe

Answered by:

Question

User1466256281 posted
it is possible run a cmd (command line ) using web page if yes how to run

Answers

User258846623 posted
You can’t do that sort of a thing and you shouldn’t be doing it either. ASP.Net is a server technology. All .Net code runs on the server and is converted to HTML + Javascript when it’s end to the web browser. You should consider writing a simple .Net Windows Applications (which could be deployed on the clients) or using ‘Click Once Deployment’ Mark as answer, if found useful Cheers, Sudhir

All replies

User377791177 posted
1. create a batch file (.bat file) and write your command inside. 2. execute this bat file using Process class. It’ll run on the server at a specified path.

System.Diagnostics.Process si = new System.Diagnostics.Process(); si.StartInfo.WorkingDirectory = "c:\\"; si.StartInfo.UseShellExecute = false; si.StartInfo.FileName = "cmd.exe"; si.StartInfo.Arguments = "/c dir"; si.StartInfo.CreateNoWindow = true; si.StartInfo.RedirectStandardInput = true; si.StartInfo.RedirectStandardOutput = true; si.StartInfo.RedirectStandardError = true; si.Start(); string output = si.StandardOutput.ReadToEnd(); si.Close(); Response.Write(output);
Althought this might seen to run on your local machine. A word of caution, It's not advisable to do this on your server , as you might run into security / permissions (ntfs) etc.
If you have the required ntfs permissions etc, then you might want to try putting all your commands in a batch file (.bat) and then use the above mechanism to execute your batch file, so that it will accomplish what you are looking to do.
Mak as answer, if useful.

Источник

Читайте также:  Https peo roskazna ru course view php id 326
Оцените статью