wolframscriptのmanの内容 [Wolfram Language]
こういう内容だ。
wolframscript(1) wolframscript(1)
NAME
wolframscript - command-line script interpreter for Wolfram Language
SYNOPSIS
wolframscript -code code [-cloud [cloudbase]] [-local [kernelpath]
[arg1 ...]
wolframscript -file file|url [-cloud cloudbase] [-local [kernelpath]]
[arg1 ...]
wolframscript -api url|uuid|file [-cloud [cloudbase]] [-local [kernel-
path]] [-args key=value ...]
wolframscript -function code [-cloud [cloudbase]] [-local [-kernel-
path]] [-signature type ...] [-args values ...]
DESCRIPTION
wolframscript runs Wolfram Language code, functions, and deployed APIs,
either locally or in the cloud, allowing input from standard input,
command-line arguments, files, URLs, etc.
EXAMPLES
Code from Command Line
Evaluate the Wolfram Language code 2+2 on a local Wolfram Engine:
$ wolframscript -code 2+2
4
Evaluate the Wolfram Language code 2+2 in the Wolfram Cloud, prompting
for authentication as needed:
$ wolframscript -cloud -code 2+2
4
Evaluate Wolfram Language code locally, escaping input for the shell:
$ wolframscript -code 'StringReverse["hello"]'
"olleh"
Evaluate code and put the results in a file:
$ wolframscript -code 'ExportString[Graphics3D[Sphere[ ]], \
"PNG"]' > file.png
Code from File
Evaluate Wolfram Language code from a file, returning the last result
generated:
$ wolframscript -file test.wl
12345
Take code from a local file, but run it in the cloud:
$ wolframscript -cloud -file test.wl
12345
Take code from a file in the cloud, but run it locally:
$ wolframscript -file http://wolfr.am/535sxfw4
12345
Script Files
A file set up to execute Wolfram Language code locally:
#!wolframscript
Print[2+2]
Create a file to execute Wolfram Language code in the Wolfram Cloud:
#!wolframscript -cloud
Print[2+2]
Create a file that uses a command-line argument:
#!wolframscript
Print[ToExpression[$ScriptCommandLine[[1]]^2]
Create a file giving a function whose arguments come from the command
line:
#!wolframscript -function -signature City City
Print[GeoDistance[#1, #2]]&
Interactive Operation
Run Wolfram Language in an interactive REPL:
$ wolframscript
WolframEngine 11.0.0 for Mac OS X x86 (64-bit)
Copyright 1988-2016 Wolfram Research, Inc.
In[1]:= 2+2
Out[1]= 4
In[2]:=
APIs
Run a cloud API:
$ wolframscript -api https://wolfr.am/bNvKWq2U -args x=1 y=2
3
Get the code for an API from the cloud, but run the API locally:
$ wolframscript -api https://wolfr.am/bNvKWq2U -local -args x=1 y=2
3
Additional Examples
Reverse the string on each line of an input file, writing the result to
another file:
$ wolframscript -function StringReverse -linewise < file1 > file2
OPTIONS
Code Options
-c, -code code
Give Wolfram Language code to execute.
-f, -file file
Give a file containing Wolfram Language code to execute.
-api url|uuid|file
Use an API at the specified URL, or coming from a cloud or local
object with the specified UUID, or coming from the specified lo-
cal file. Use arguments key=value ....
-fun, -function code [-s|signature type ...] [-args|-- value ...]
Use a function whose arguments are the strings value a|, inter-
preted as being of types type a|. If no signature is given, all
arguments are assumed to be strings. Signature types can be any
of $InterpreterTypes.
Execution Options
-o, -cloud [cloudbase]
Execute code in the cloud, using the specified cloud base. By
default, cloudbase is http://wolframcloud.com.
-l, -local [kernelpath]
Execute code locally, using the specified path to the Wolfram
Engine kernel.
-format [type]
Specify the format in which to give output.
-linewise
Execute code on each line of standard input that is read.
-print [all]
When running a script, print the result from executing the last
line of the script, or each line if all is given.
-timeout seconds [value]
Specify the number of seconds to allow for execution. Return
value if the time is exceeded.
-v, -verbose
Print additional information during execution.
Utility Options
-h, -help
Print help text.
-auth, -authenticate [wolframid [password]] [-cloud cloudbase]
Authenticate with the cloud, specifying a particular Wolfram ID
and password, and prompting if they are not given. Different au-
thentication can be specified for different clouds.
-config, -configure [key=value ...]
Configure wolframscript by specifying values for particular con-
figuration variables keys.
-disconnect [-cloud cloudbase]
Disconnect from the cloud, removing authentication information.
DETAILS
Wolfram Language Scripts
All standard options can be used in #!wolframscript scripts.
With #!wolframscript -function ..., each argument to the function can
be given on the script command line.
With #!wolframscript -api ..., the parameters of the API can be given
on the script command line in the form -key value ....
The exit code from executing a script can be specified using Ex-
it[code].
Without -print, no output will be sent to stdout unless this is explic-
itly done using Print[expr].
With the option -print, the result from the last line in the script is
sent to stdout.
With the option -print all, results from each line in the script are
sent to stdout when they are generated.
The -linewise option can be used to run the script multiple times, tak-
ing a single line of stdin as input each time.
Command-Line Input
Input given to a script on standard input can be accessed in Wolfram
Language code using $ScriptInputString.
Arguments given on the command line can be accessed using $ScriptCom-
mandLine.
Output Formatting
The default setting for TotalWidth is Infinity.
API Parameters
If an API supports extended parameters such as x-url, x-format, and
_timeout, these can be given in wolframscript -api.
Code Location
In wolframscript -api uuid, LocalObject["uuid"] is used if it exists,
otherwise CloudObject["uuid"].
FILES
Configuration file:
WOLFRAM LANGUAGE VARIABLES
The following variables are set when wolframscript begins execution.
$CommandLine
A list of strings giving the complete command line used.
$ScriptCommandLine
A list of command-line arguments intended for the script being
run. These come after options given with -option.
ENVIRONMENT VARIABLES
WOLFRAMSCRIPT_AUTHENTICATIONPATH
The path to files storing authentication information.
WOLFRAMSCRIPT_CONFIGURATIONPATH
The path to files storing persistent configuration information.
WOLFRAMSCRIPT_CLOUDBASE
The default cloud base to use in wolframscript.
WOLFRAMSCRIPT_KERNELPATH
The path to the default local Wolfram Engine kernel executable.
wolframscript(1)
もちろん
https://reference.wolfram.com/language/ref/program/wolframscript.html.ja
https://reference.wolfram.com/language/tutorial/WolframLanguageScripts.html
https://reference.wolfram.com/language/tutorial/UsingATextBasedInterface.html
を読む方が良い。
wolframscript(1) wolframscript(1)
NAME
wolframscript - command-line script interpreter for Wolfram Language
SYNOPSIS
wolframscript -code code [-cloud [cloudbase]] [-local [kernelpath]
[arg1 ...]
wolframscript -file file|url [-cloud cloudbase] [-local [kernelpath]]
[arg1 ...]
wolframscript -api url|uuid|file [-cloud [cloudbase]] [-local [kernel-
path]] [-args key=value ...]
wolframscript -function code [-cloud [cloudbase]] [-local [-kernel-
path]] [-signature type ...] [-args values ...]
DESCRIPTION
wolframscript runs Wolfram Language code, functions, and deployed APIs,
either locally or in the cloud, allowing input from standard input,
command-line arguments, files, URLs, etc.
EXAMPLES
Code from Command Line
Evaluate the Wolfram Language code 2+2 on a local Wolfram Engine:
$ wolframscript -code 2+2
4
Evaluate the Wolfram Language code 2+2 in the Wolfram Cloud, prompting
for authentication as needed:
$ wolframscript -cloud -code 2+2
4
Evaluate Wolfram Language code locally, escaping input for the shell:
$ wolframscript -code 'StringReverse["hello"]'
"olleh"
Evaluate code and put the results in a file:
$ wolframscript -code 'ExportString[Graphics3D[Sphere[ ]], \
"PNG"]' > file.png
Code from File
Evaluate Wolfram Language code from a file, returning the last result
generated:
$ wolframscript -file test.wl
12345
Take code from a local file, but run it in the cloud:
$ wolframscript -cloud -file test.wl
12345
Take code from a file in the cloud, but run it locally:
$ wolframscript -file http://wolfr.am/535sxfw4
12345
Script Files
A file set up to execute Wolfram Language code locally:
#!wolframscript
Print[2+2]
Create a file to execute Wolfram Language code in the Wolfram Cloud:
#!wolframscript -cloud
Print[2+2]
Create a file that uses a command-line argument:
#!wolframscript
Print[ToExpression[$ScriptCommandLine[[1]]^2]
Create a file giving a function whose arguments come from the command
line:
#!wolframscript -function -signature City City
Print[GeoDistance[#1, #2]]&
Interactive Operation
Run Wolfram Language in an interactive REPL:
$ wolframscript
WolframEngine 11.0.0 for Mac OS X x86 (64-bit)
Copyright 1988-2016 Wolfram Research, Inc.
In[1]:= 2+2
Out[1]= 4
In[2]:=
APIs
Run a cloud API:
$ wolframscript -api https://wolfr.am/bNvKWq2U -args x=1 y=2
3
Get the code for an API from the cloud, but run the API locally:
$ wolframscript -api https://wolfr.am/bNvKWq2U -local -args x=1 y=2
3
Additional Examples
Reverse the string on each line of an input file, writing the result to
another file:
$ wolframscript -function StringReverse -linewise < file1 > file2
OPTIONS
Code Options
-c, -code code
Give Wolfram Language code to execute.
-f, -file file
Give a file containing Wolfram Language code to execute.
-api url|uuid|file
Use an API at the specified URL, or coming from a cloud or local
object with the specified UUID, or coming from the specified lo-
cal file. Use arguments key=value ....
-fun, -function code [-s|signature type ...] [-args|-- value ...]
Use a function whose arguments are the strings value a|, inter-
preted as being of types type a|. If no signature is given, all
arguments are assumed to be strings. Signature types can be any
of $InterpreterTypes.
Execution Options
-o, -cloud [cloudbase]
Execute code in the cloud, using the specified cloud base. By
default, cloudbase is http://wolframcloud.com.
-l, -local [kernelpath]
Execute code locally, using the specified path to the Wolfram
Engine kernel.
-format [type]
Specify the format in which to give output.
-linewise
Execute code on each line of standard input that is read.
-print [all]
When running a script, print the result from executing the last
line of the script, or each line if all is given.
-timeout seconds [value]
Specify the number of seconds to allow for execution. Return
value if the time is exceeded.
-v, -verbose
Print additional information during execution.
Utility Options
-h, -help
Print help text.
-auth, -authenticate [wolframid [password]] [-cloud cloudbase]
Authenticate with the cloud, specifying a particular Wolfram ID
and password, and prompting if they are not given. Different au-
thentication can be specified for different clouds.
-config, -configure [key=value ...]
Configure wolframscript by specifying values for particular con-
figuration variables keys.
-disconnect [-cloud cloudbase]
Disconnect from the cloud, removing authentication information.
DETAILS
Wolfram Language Scripts
All standard options can be used in #!wolframscript scripts.
With #!wolframscript -function ..., each argument to the function can
be given on the script command line.
With #!wolframscript -api ..., the parameters of the API can be given
on the script command line in the form -key value ....
The exit code from executing a script can be specified using Ex-
it[code].
Without -print, no output will be sent to stdout unless this is explic-
itly done using Print[expr].
With the option -print, the result from the last line in the script is
sent to stdout.
With the option -print all, results from each line in the script are
sent to stdout when they are generated.
The -linewise option can be used to run the script multiple times, tak-
ing a single line of stdin as input each time.
Command-Line Input
Input given to a script on standard input can be accessed in Wolfram
Language code using $ScriptInputString.
Arguments given on the command line can be accessed using $ScriptCom-
mandLine.
Output Formatting
The default setting for TotalWidth is Infinity.
API Parameters
If an API supports extended parameters such as x-url, x-format, and
_timeout, these can be given in wolframscript -api.
Code Location
In wolframscript -api uuid, LocalObject["uuid"] is used if it exists,
otherwise CloudObject["uuid"].
FILES
Configuration file:
WOLFRAM LANGUAGE VARIABLES
The following variables are set when wolframscript begins execution.
$CommandLine
A list of strings giving the complete command line used.
$ScriptCommandLine
A list of command-line arguments intended for the script being
run. These come after options given with -option.
ENVIRONMENT VARIABLES
WOLFRAMSCRIPT_AUTHENTICATIONPATH
The path to files storing authentication information.
WOLFRAMSCRIPT_CONFIGURATIONPATH
The path to files storing persistent configuration information.
WOLFRAMSCRIPT_CLOUDBASE
The default cloud base to use in wolframscript.
WOLFRAMSCRIPT_KERNELPATH
The path to the default local Wolfram Engine kernel executable.
wolframscript(1)
もちろん
https://reference.wolfram.com/language/ref/program/wolframscript.html.ja
https://reference.wolfram.com/language/tutorial/WolframLanguageScripts.html
https://reference.wolfram.com/language/tutorial/UsingATextBasedInterface.html
を読む方が良い。
An Elementary Introduction to the Wolfram Language
- 作者: Stephen Wolfram
- 出版社/メーカー: Wolfram Media Inc
- 発売日: 2017/04/01
- メディア: ペーパーバック