小编Squ*_*man的帖子

如何在PowerShell中输出内容

我正在批处理文件中运行PowerShell脚本.该脚本获取一个网页并检查该页面的内容是否为字符串"OK".

PowerShell脚本向批处理脚本返回错误级别.

批处理脚本由ScriptFTP执行,ScriptFTP是一个FTP自动化程序.如果发生错误,我可以让ScriptFTP通过电子邮件将完整的控制台输出发送给管理员.

在PowerShell脚本中,如果它不是"OK",我想从网站输出返回值,因此错误消息包含在控制台输出中,因此也包含在状态邮件中.

我是PowerShell的新手,不知道要使用哪个输出函数.我可以看到三个:

  • 写主机
  • 写输出
  • 写入错误

用什么来写Windows等价的东西是正确的stdout

windows powershell

197
推荐指数
5
解决办法
54万
查看次数

命令提示符/批处理 - 使用顺序编号重命名多个文件

假设我有多个文件

filename.a.txt
filename.b.txt
filename.c.txt
Run Code Online (Sandbox Code Playgroud)

我想运行一个以所有 .txt 文件为目标的批处理文件,并将它们重命名为我在自定义 %filename% var 中设置的任何内容

filename.1.txt
filename.2.txt
filename.3.txt
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已经写了这个:

set filename=FileTitle
for /r %%i in (*.txt) do call ren %%i %filename%.txt
Run Code Online (Sandbox Code Playgroud)

它可以工作,但问题是它只是选取第一个 .txt 文件并为其提供 FileTitle 文件名,仅此而已。我无法弄清楚如何批量重命名所有 .txt 文件,并为它们提供唯一的序列号作为输出的前缀/后缀/自定义变量%filename%.txt,例如%filename%-%uniquesuffix%.txt. 所以我需要设置某种变量,为每个文件提供一个唯一的数字,例如按字母顺序从 1 到 99(cmd 提示选择文件的默认顺序)。

我确实搜索了其他答案,但它们只显示了如何向重命名的文件添加全局/相同前缀。

windows batch-file batch-rename

6
推荐指数
1
解决办法
1万
查看次数

使用脚本登录网站

我实际上正在编写一个 Windows 脚本,单击该脚本将打开我的默认 Web 浏览器,打开一个页面,输入我的登录详细信息,然后提交表单。

到目前为止我能做的就是用这个打开浏览器:

explorer http:\\outlook.com\website.com
Run Code Online (Sandbox Code Playgroud)

由于我找不到任何说明如何执行此操作的资源,因此我查看了 python 脚本并找到了两个库,即。urllibwebbrowser。我知道这urllib是用于抓取网站。但我不确定如何在网络浏览器中模拟相同的内容。该webbrowser库只有在新选项卡等中打开页面的命令。

请告诉我如何使用 python 或 windows 脚本完成此任务。

编辑:我的用户名和密码保存在我的浏览器中,以便它自动填充。我只想模拟 'ENTER' 按键。

python

5
推荐指数
1
解决办法
3万
查看次数

文件名包含#导致Spring Batch StaxEventItemReader无法打开

我在名称中有一个带#的输入文件(UPX#L.xxxxx001.xml).Spring Batch StaxEventItemReader无法打开此文件.反正有没有逃脱这个特殊的角色?请指教.

这是我的豆子

 <bean id="myItemReader" parent="myItemReaderParent" scope="step">

        <property name="resource" value="file:#{jobParameters['toolf.input.file.name']}"/>

 </bean>

<bean id="myItemReaderParent" class="org.springframework.batch.item.xml.StaxEventItemReader" scope="prototype">

    <property name="fragmentRootElementName" value="MyRec"/>

    <property name="unmarshaller" ref="myUnmarshaller"/>

</bean>
Run Code Online (Sandbox Code Playgroud)
[INFO ]org.springframework.jms.listener.DefaultMessageListenerContainer#0-1[2015-02-05 10:27:23,487] - Sending notification for start of JobExecution: id=52760, version=1, startTime=Thu Feb 05 10:27:23 EST
 2015, endTime=null, lastUpdated=Thu Feb 05 10:27:23 EST 2015, status=STARTED, exitStatus=exitCode=UNKNOWN;exitDescription=, job=[JobInstance: id=52759, version=0, JobParameters=[

{toolf.institutionSymbol=YDX , toolf.projectId=013832, toolf.orderId=678161, toolf.transmissionDate=20150205 10:27:23.392 EST, toolf.input.file.name=/batchdata/dataload/xxx/in/tool/UPX#L.xxxxx001.xml, toolf.out.root.directory=/batchdata/output, toolf.out.input.file.name.without.path=YDX.013832.678161.YbpUsSI#Picklists.d20150204.t140001.xml, toolf.out.working.directory/batchdata/dataload/xxx/in/tool/, timestamp=1423150043392}

], Job=[timeOfOrderLabelJob]]
[INFO ]org.springframework.jms.listener.DefaultMessageListenerContainer#0-1[2015-02-05 10:27:23,576] - Executing step: [toolPrologue]
[ERROR]org.springframework.jms.listener.DefaultMessageListenerContainer#0-1[2015-02-05 10:27:23,607] - Encountered an …
Run Code Online (Sandbox Code Playgroud)

java linux spring spring-batch

5
推荐指数
1
解决办法
918
查看次数

打字稿:tsc 不是内部或外部命令,也不是可运行的程序或批处理文件

我是打字稿的初学者。我无法编译类型脚本文件。

当我在 VS Code 中按 Ctrl+Shift+B 时,出现错误“tsc 无法识别”

我在下载成绩单时使用了 npm。

C:\Users\sramesh>npm install -g typescript
C:\Users\sramesh\AppData\Roaming\npm\tsserver -> C:\Users\sramesh\AppData\Roaming\npm\node_modules\typescript\bin\tsserver
C:\Users\sramesh\AppData\Roaming\npm\tsc -> C:\Users\sramesh\AppData\Roaming\npm\node_modules\typescript\bin\tsc
C:\Users\sramesh\AppData\Roaming\npm
`-- typescript@2.1.5
Run Code Online (Sandbox Code Playgroud)

这是我的 tasks.json 文件

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "C:\\Users\\sramesh\\AppData\\Roaming\\npm\\node_modules\\typescript\\bin\\tsc",
    "isShellCommand": true,
    "args": [],
    "showOutput": "silent",
    "problemMatcher": "$tsc"
}
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮忙吗?

node.js typescript tsc

5
推荐指数
3
解决办法
3万
查看次数

如何在批处理文件中"打开"

我有一个Windows PowerShell脚本,可以在服务器上提供给我的用户.我不希望他们必须出去找到PS脚本,右键单击并单击"使用powershell运行"或执行"打开方式".Windows(至少Win 7)默认程序是记事本.

我想制作一个批处理文件来执行此操作.我试过了:

start "c:\myfile.ps1" powershell.exe
Run Code Online (Sandbox Code Playgroud)

以及其他一些变体,但我所能做的就是启动powershell,或者在默认程序notepad中打开我的文件.

任何建议表示赞赏!谢谢!

奖金问题:如果我以管理员身份运行我的批处理文件,它还会以管理员身份运行我的PS脚本吗?

windows powershell

5
推荐指数
1
解决办法
2702
查看次数

在Windows命令提示符/ PowerShell中下载大文件

我现在有点没钱了...

尝试1

在Powershell中使用iwr。它可以工作,显示进度,但速度慢10倍,直到文件在内存中才刷新:(。

 powershell -command "& { iwr https://github.com/mitchellspryn/AirsimHighPolySuv/releases/download/V1.0.0/SUV.zip -OutFile SUV.zip }"
Run Code Online (Sandbox Code Playgroud)

尝试2

在Powershell中使用.Net webclient。它有效,但是没有任何进展,您无法通过Ctrl + C :(。终止。

powershell -command "& { (New-Object System.Net.WebClient).DownloadFile('https://github.com/mitchellspryn/AirsimHighPolySuv/releases/download/V1.0.0/SUV.zip', 'SUV.zip') }"
Run Code Online (Sandbox Code Playgroud)

尝试3

在Powershell中使用BITS传输。它可以工作,显示进度并且几乎完美……直到您发现它神秘地在GitHub上不起作用(错误禁止403)!

powershell -command "& { Start-BitsTransfer -Source https://github.com/mitchellspryn/AirsimHighPolySuv/releases/download/V1.0.0/SUV.zip -Destination SUV.zip }"
Run Code Online (Sandbox Code Playgroud)

powershell command-line webclient-download microsoft-bits

5
推荐指数
2
解决办法
2220
查看次数

从 cmd 行启动时,为什么在 Windows 上运行 Shiny 会启动两个 Rscript 进程?

当我启动R运行一个脚本shiny从应用程序cmd行,它似乎推出2个的实例Rscript.exe?我总是可以杀死两者中较小的一个并且应用程序继续运行?有人可以详细说明幕后实际发生的事情,或者告诉我我做错了什么导致双重流程?


超级简单.R

require(shiny)

app <- shinyApp(
  ui = bootstrapPage(
    numericInput('n', 'Number of obs', 100),
    plotOutput('plot')
  ),
  server = function(input, output) {
    output$plot <- renderPlot({ hist(runif(input$n)) })
  }
)

runApp(app, launch.browser = FALSE, port = 1234, host = "10.123.4.56")
Run Code Online (Sandbox Code Playgroud)

现在,如果我通过以下cmd线路启动它:

START Rscript --vanilla C:\Users\Jason\Projects\super_simple.R
Run Code Online (Sandbox Code Playgroud)

此时,我可以将浏览器指向http://10.123.4.56:1234并查看该应用程序。但是,如果我通过以下方式tasklist /FI "imagename eq rscript*"查看正在运行的进程:我看到两个 Rscript.exe进程:

流程

然而,我确定的是,我总是可以杀死两者中较小的一个(例如taskkill /pid 9360 /f),而该应用程序仍然可以完整运行?注意:我尝试通过在后台启动命令,START \b ...但结果是一样的。

cmd r shiny shiny-server

5
推荐指数
1
解决办法
364
查看次数

从外部函数批处理返回字符串

我有两个批处理文件。一个是主(调用者)文件,一个是函数。该函数接受一个参数,执行一些操作,然后我想将字符串返回给调用者 (main.bat)。%ERRORLEVEL% 不是一个选项,因为它只能返回整数。

main.bat:
call function.bat hello
function.bat:
REM some code.......
[HERE THE THE CODE TO RETURN A STRING TO CALLER FILE]
好像是基本操作,所以一定有办法。另外,我不喜欢用输出制作文件并在 main.bat 中读取它,因为我想让它作为一个易于使用的功能工作。

windows function batch-file

5
推荐指数
1
解决办法
4888
查看次数

powershell相当于cmd中的“%*”是什么?

如何在 powershell 函数中编写以下 cmd 脚本:

@echo off
C:\bin\command.exe %*
Run Code Online (Sandbox Code Playgroud)

Powershell脚本:

function f{
    [CmdletBinding()] Param()
    # .. Code? ...
}
Run Code Online (Sandbox Code Playgroud)

powershell scripting cmd batch-file

4
推荐指数
1
解决办法
1334
查看次数