Перевод exec filename execute a script file

Перевод exec filename execute a script file

execute — ex‧e‧cute [ˈekskjuːt] verb [transitive] 1. to do what is written in a contract, plan etc: • The directors make the decisions but the managers have to execute them. • UK companies with a proven management ability to execute a business plan 2.… … Financial and business terms

Script.NET — Тип Язык программирования Операционная система Windows 98 или старше Последняя версия Версия 1.0 (17 декабря 2007) Лицензия LGPL … Википедия

execute — 1. To run a program, command, or script. 2. One of the permissions assigned to a file or directory; you can only execute a file when the execute permission is enabled … Dictionary of networking

script — A small program or macro invoked at a particular time. For example, a login script may execute the same specific set of instructions every time a user logs into a network. A communications script may send user identification information to… … Dictionary of networking

Shell script — This article is about scripting in UNIX like systems. For batch programming in DOS, OS/2 and Windows, see Batch file. For batch programming in Windows PowerShell shell, see Windows PowerShell#Scripting. A shell script is a script written for the… … Wikipedia

Interpréteur de script — Interprète (informatique) Pour les articles homonymes, voir Interprète et Interpréteur. Un interprète, ou interpréteur (voir infra), est un outil informatique ayant pour tâche d analyser, de traduire et d exécuter un programme écrit dans un… … Wikipédia en Français

Java script — JavaScript Ne doit pas être confondu avec Java (langage). Apparu en … Wikipédia en Français

Windows Script Host — The Icon For Windows Script Host The Microsoft Windows Script Host (WSH) is an automation technology for Microsoft Windows operating systems that provides scripting capabilities comparable to batch files, but with a greater range of supported… … Wikipedia

Windows Script File — Infobox file format name = Windows Script File extension = .wsf owner = Microsoft genre = Scripting container for = ScriptsA Windows Script File (WSF) is a file type used by the Microsoft Windows Script Host. It allows mixing scripting languages… … Wikipedia

Langage De Script — Un langage de script est un langage de programmation qui permet de manipuler les fonctionnalités d un système informatique configuré pour fournir à l interpréteur de ce langage un environnement et une interface qui déterminent les possibilités de … Wikipédia en Français

Langages de script — Langage de script Un langage de script est un langage de programmation qui permet de manipuler les fonctionnalités d un système informatique configuré pour fournir à l interpréteur de ce langage un environnement et une interface qui déterminent… … Wikipédia en Français

Источник

Urban Terror Forums: exec : execute a script file — Urban Terror Forums

  • Home
  • Forums home
UrT Forums
  • Forum Guidelines
  • Active Content
  • Mark Board As Read
  • RSS feeds
Forums Search
  • Advanced Search
Forums Users
  • Forums Staff
  • UrT Members
  • Today Posters
Info & Contact
communities
Help UrT

exec : execute a script file Rate Topic:

a server admin problem

#1 squiggles

I have followed the instructions on this site’s manual for server admins with a windows system. When i run the ioquake3ded.exe shortcut i made the console runs until it reaches a line that states:

«exec : execute a script file»

I’m not sure what this means or how to fix it. Any help would be appreciated.

#2 thelionroars

  • QA member
  • Account: thelionroars
  • Country:
  • Joined: 21-September 11
  • Posts: 852 Notoriety: basic —>

#3 squiggles

thelionroars, on 06 October 2013 — 01:05 AM, said:

When I run the shortcut a long section of text appears and then the following text ends the script:

14564 files in pk3 files
execing default.cfg
execing q3config.cfg
couldn’t exec autoexec.cfg
Hunk_Clear: reset the hunk ok
. detecting CPU, found generic
Detecting CPU cores: OK: Found 2 CPU cores: Using user selected single core: 2
— Common Initialization Complete —
Winsock Initialized
Opening IP socket: localhost:27960
Hostname: acer-42041e6643
IP: 192.168.1.70
Working directory: C:\Program Files\UrbanTerror42
exec : execute a script file

#4 thelionroars

  • QA member
  • Account: thelionroars
  • Country:
  • Joined: 21-September 11
  • Posts: 852 Notoriety: basic —>

It all looks normal except the last line, where it seems to be giving you the usage for the \exec command — probably because you have used +exec in the parameter list without an argument.

Can you post the line you have put in your shortcut, like I asked. I assume you are following http://www.urbanterr. server-install/ — so you will have included a line like this:

can you copy and paste what you have put in the shortcut so that I or someone else can see what you’ve done wrong.

#5 squiggles

thelionroars, on 06 October 2013 — 08:42 PM, said:

It all looks normal except the last line, where it seems to be giving you the usage for the \exec command — probably because you have used +exec in the parameter list without an argument.

Can you post the line you have put in your shortcut, like I asked. I assume you are following http://www.urbanterr. server-install/ — so you will have included a line like this:

can you copy and paste what you have put in the shortcut so that I or someone else can see what you’ve done wrong.

Here the line. For some reason there is no ioquake 3 but a similar file

«C:\Program Files\UrbanTerror42\Quake3-UrT-Ded.exe» +seta net_port 27960 +exec corsairs cavern.CFG

#6 [dswp] JRandomNoob

  • verified user
  • Account: jrandomnoob
  • Main tag: [dswp]
  • Country:
  • Joined: 26-December 10
  • Posts: 875 Notoriety: basic —>

«C:\Program Files\UrbanTerror42\Quake3-UrT-Ded.exe» +seta net_port 27960 +exec corsairs cavern.CFG

If you have spaces in the filename, you have to use quotes around it: +exec «corsairs cavern.CFG»

#7 thelionroars

  • QA member
  • Account: thelionroars
  • Country:
  • Joined: 21-September 11
  • Posts: 852 Notoriety: basic —>

What JRandomN00b said. Actually I would remove the space from the filename altogether, and then replace the name in the shortcut.

squiggles, on 07 October 2013 — 12:51 AM, said:

ioquake was 4.1, the documentation probably needs updating.

Источник

Executing shell commands, script files, and executables in Go

In this article, we are going to learn how to execute external shell commands, script files and executable files from a Go program using built-in os/exec package

While working with any programming language, you have to admit that not everything can be written in a program. Sometimes, you need to use external programs to perform some job that your program was not intended to do.

For example, to find the current user of the system, you can use whoami bash command that returns the username. You wouldn’t write a program to just find that out with complicated logic and OS dependencies.

💡 FYI, Go provides os/ user package to get the information about the system users and user groups. You can use user. Current () function to get information about the current user of a system.

Sometimes, you have a program written in different languages like JavaScript or Bash that you want to execute from a Go program and read the output once the program finishes successfully.

If you are working with Node.js, then you are familiar with child_process built-in package. In Go, we have exec package provided by the os package. The exec package provides APIs to lookup programs and executables to run them and consume the output.

LookPath function

The LookPath function returns the path of an executable file if it finds one under registered PATH directories, as long as the file argument does not contain any slashes ( / ). If file contains slashes, then the path will be resolved relatively or absolutely depending on the file value itself.

Let’s try to look for the go executable in our system. This is more like running the which go Bash command.

The above result in my case returns /usr/local/go/bin/go since I installed Go using the standard Go installation process. If an file executable does not exist in PATH, or file path can not be resolved or Go does not have sufficient permissions to access the file or directory, an error will be thrown.

This function is useful while working with Cmd struct that provides the APIs to execute external commands and programs.

Cmd Structure

The Cmd structure provided by the exec package does the configuration of how a command, executable or an external program supposed to run within our Go program. Let’s have a quick look at its properties.

Fields of the Cmd structure should be self-explanatory. To execute a command, we need to create a struct of Cmd type and execute some methods on it. Let’s create a Cmd struct that runs go version command.

In the above program, we have created a basic Cmd struct which points to standard Go executable path. The Args field contains the list of arguments to invoke the Go executable. We have set STDOUT and STDERR to os.Stdout that will spit out the result of the execution to the terminal.

The Args value can be confusing. Since it is a slice of string , we have provided the appropriate type. However, the first value of this slice seems odd. This is because, while running a program or an executable, the first value of the command arguments is always the file itself.

💡 If you are familiar with Bash scripts ( lesson here), this value is read from the $0 variable in the Bash script. You can see command-line arguments of a running Go script from os. Args variable and try to inspect the first value.

The Cmd structure implements the String method which returns the final composed command. Let’s see the output of the above program.

If you are confused about the output of the go version command, then do not panic. The cmdGoVer struct constructs the command but does not execute it. To execute the command, we need to use other built-in methods.

💡 The reason we are creating a pointer to the struct is because the methods Cmd structure implements have a pointer receiver. Not that it really matters because we discussed about this in methods lesson but it’s good for safety if iterfaces are involved.

Run method

The Cmd.Run method runs the command and throws an error if the command could not successfully run. This error does not contain standard output.

By running this program, we get the following output.

This is the standard output of the go version command which was redirected to the terminal output since we have set the Stdout field of the struct to os.Stdout . The process will be blocked until the command exits.

Start and Wait methods

If you are not a big fan of blocking the process while executing the external command, then you can always use the goroutines and channels. However, there is a simple approach.

Instead of running a command in the main process, it can be run in the background using Cmd.Start method. It starts the command but does not wait for it to exit.

While the command is running in the background, we can do other stuff. But how do we know when it exits and what if our main process exits before the command finishes its execution?

The Cmd.Wait method waits for the command to finish if not already finished.

The error will be non-nil if there was an error executing the command. The Wait method also waits until all the copy operations of STDOUT and STDERR are finished.

This time, let’s execute sleep command with 3 seconds period. Since this command will block the process for 3 seconds and make our program unusable, it better to run this command in the background.

We are also going to create a sleep.sh Bash script file which has this program. We will keep this script in the current directory and pass the path to this script to our Go program to execute.

In the program above, we have created a command that executes sleep.sh file using a standard interpreter mentioned in the hashbang. Once the command is started in the background using cmd.Start() , it does not block the process and we can perform other operations like running a for loop.

Since we do not know whether the command has been successfully completed at the end of the for loop, we need to wait for it to successfully complete using cmd.Wait() call. By executing this program, we get the following result.

If you do not see the Hello. string in the output, that means the command was executed before the for loop could finish. The output is still somewhere in the result, you can pipe it to grep «Hello. » to verify.

Command function

In most cases, you would be using exec.Command function to return an instance of Cmd structure. It takes very few arguments and returns a pointer of Cmd . This function has the following syntax.

The name argument is similar to the Path field of the Cmd structure but it has one added benefit. If the name argument does not contain any / , then the path of the command ( executable) is resolved using LookPath method.

Command function is a variadic function because it accepts an arbitrary number of arguments. The arg is similar to Args field of the Cmd structure, but this time, we do not need to pass the first Args value that specified the path to the executable file.

Since this command only takes two kinds of arguments, other fields of the struct can be overridden later. Let’s modify our earlier example.

The program above yields the same output.

Output method

In most cases, you just don’t want to run a program but to read its output. So far, our program is outputting the result to standard output and we are not able to catch it in our program. Well, Output method solves this problem.

The Output method runs the command ( just like Run method) and waits until it finishes. If the command was successfully executed, it returns the standard output as a slice of bytes. If there was an error in the command execution, it returns the error.

💡 For Output method to run, the Stdout field of the Cmd struct should be nil else it will throw an error Stdout already set . Also, if the command redirects its execution result to standard error, it will be contained in the error as long as Stderr field of the Cmd was not set beforehand. Read more from here.

Since cmd.Output returns two values, we needed to modify our if/else statement. The %s formatting operator converts slice of bytes into printable characters. This program also yields the same result.

CombinedOutput method

If you wish to capture the standard error as well, then you can use CombinedOutput method. This method behaves exactly like the Output method and has the same signature.

There are other useful Cmd structure properties, functions, and methods available in exec package that you should also take a look at.

Источник

Оцените статью
( Пока оценок нет )
Поделиться с друзьями
Uchenik.top - научные работы и подготовка
0 0 голоса
Article Rating
Подписаться
Уведомить о
guest
0 Комментарий
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии