<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Soul Of Free Loop &#187; 权限</title>
	<atom:link href="https://zohead.com/archives/tag/authority/feed/" rel="self" type="application/rss+xml" />
	<link>https://zohead.com</link>
	<description>Uranus Zhou&#039;s Blog</description>
	<lastBuildDate>Sat, 19 Jul 2025 15:42:46 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.8</generator>
	<item>
		<title>Cygwin环境中调用VBScript的权限问题</title>
		<link>https://zohead.com/archives/cygwin-vbscript-permission/</link>
		<comments>https://zohead.com/archives/cygwin-vbscript-permission/#comments</comments>
		<pubDate>Sun, 01 Dec 2013 14:41:02 +0000</pubDate>
		<dc:creator><![CDATA[Uranus Zhou]]></dc:creator>
				<category><![CDATA[shell]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[技术]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[cygwin]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[MSYS]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[权限]]></category>

		<guid isPermaLink="false">http://zohead.com/?p=636</guid>
		<description><![CDATA[本文同步自（最佳显示效果请点击）：https://zohead.com/archives/cygwin-vbscript-permission/ 之前因为一个项目需求，需要在 Windows 上使用 Bash 脚本运行 Windows 上的程序，因此想到在 Cygwin 的 Bash 里实现（好吧，这确实比较令人蛋疼）。运行 Cygwin 中的 bash.exe 调用脚本，并启动另一个 VBScript 脚本来对一个 Excel 文件进行修改处理（使用 Windows 的原因了）。 刚开始通过 cscript.exe 命令在 Windows 自带的命令提示符中运行 VBScript 还比较顺便 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>本文同步自（最佳显示效果请点击）：<a href="https://zohead.com/archives/cygwin-vbscript-permission/" target="_blank">https://zohead.com/archives/cygwin-vbscript-permission/</a></p>
<p>之前因为一个项目需求，需要在 Windows 上使用 Bash 脚本运行 Windows 上的程序，因此想到在 Cygwin 的 Bash 里实现（好吧，这确实比较令人蛋疼）。运行 Cygwin 中的 bash.exe 调用脚本，并启动另一个 VBScript 脚本来对一个 Excel 文件进行修改处理（使用 Windows 的原因了）。</p>
<p>刚开始通过 cscript.exe 命令在 Windows 自带的命令提示符中运行 VBScript 还比较顺便，能顺利打开 Excel 文件并处理成功。但通过 Cygwin 的 Bash 脚本运行之后却老是在 VBScript 的打开 Excel 文件的地方提示找不到文件打开失败，顿时非常困惑。</p>
<p>Cygwin 的 Bash 脚本例子如下，test.sh 为 Bash 脚本程序，xxx.vbs 为处理 Excel 文件的 VBScript 脚本程序，运行 VBScript 脚本前需要先读取输入并传给 VBScript 脚本作为参数：</p>
<pre class="brush: bash; title: test.sh; notranslate">
#!./bash
echo &quot;Test script...&quot;
read TESTVAL

# xxx do something xxx

read TESTLEN
echo &quot;Require length: $TESTLEN&quot;

cscript //Nologo xxx.vbs $TESTVAL

# xxx do something else xxx

read TESTEND
echo &quot;....&quot;
</pre>
<p>初步考虑是 Cygwin 开启的 shell 权限不足，为解决问题，便尝试了各种方法：</p>
<ul>
<li>建立快捷方式设置以管理员方式运行，问题依旧；</li>
<li>把 Cygwin Bash shell 换为 MSYS 的，还是同样的报错；</li>
<li>通过 runas 命令以指定用户身份运行 cscript.exe VBScript 脚本，依旧。</li>
</ul>
<p>但非常奇怪的是，我手工运行 Cygwin bash.exe 开启一个终端，然后在终端中运行 cscript 调用 VBScript 结果却又一切正常。</p>
<p>为此不得不又把目光转移到 Bash 脚本代码中，除了刚开始有两个 read 读取输入和 echo 输出操作外，并没有什么特殊的操作。实在找不到办法，就把 cscript 操作放在脚本最前面（使用固定参数，不通过读取输入的方式传入），再运行 test.sh 却惊奇的发现可以正常工作了。有点头绪了，由于运行 VBScript 必须从当前 Bash 脚本中传入参数，因此尝试着把第二个暂时不是特别必要的 read 和 echo 操作注释掉（第 7 和 第 8 行），也工作正常。</p>
<p>再经过反复测试发现 Cygwin 启动的 Bash 在运行了两次 read 操作之后再调用 VBScript 脚本就会出现权限不对的问题，只 read 一次或者完全不做 read 读取输入操作（cscript 命令放在最开始）都不会有问题。</p>
<p>现在也实在没明白两次 read 读取输入操作会导致什么系统环境不一样才使 VBScript 运行失败，Google 之后有朋友也遇到这种问题但没有正确的解答，可能这种改 read 方式并不彻底，但目前也算权宜之道了 ^_^。</p>
]]></content:encoded>
			<wfw:commentRss>https://zohead.com/archives/cygwin-vbscript-permission/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
