组保留的标签 余下为需要删除的标签
unset($oldtag[$key]);
}
}
}
if (!empty($oldtag)) {
$tagids = array();
foreach ($oldtag as $tagid => $tagname) {
$tagids[] = $tagid;
}
well_oldtag_delete($tagids, $tid);
}
$r = well_tag_process($tid, $fid, $create_tag, $tagarr);
return $r;
}
// 删除标签和绑定的主题
function well_oldtag_delete($tagids, $tid)
{
$pagesize = count($tagids);
$arrlist = well_tag_find_by_tagids($tagids, 1, $pagesize);
$delete_tagids = array(); // 删除
$tagids = array();
$n = 0;
foreach ($arrlist as $val) {
++$n;
if (1 == $val['count']) {
// 只有一个主题
$delete_tagids[] = $val['tagid'];
} else {
$tagids[] = $val['tagid'];
}
}
!empty($delete_tagids) and well_tag_delete($delete_tagids);
$arlist = well_tag_thread_find_by_tid($tid, 1, $n);
if ($arlist) {
$ids = array();
foreach ($arlist as $val) $ids[] = $val['id'];
well_tag_thread_delete($ids);
}
!empty($tagids) and well_tag_update($tagids, array('count-' => 1));
}
// 标签数据处理 $arr=新提交的数组 $tagarr=保留的旧标签
function well_tag_process($tid, $fid, $new_tags = array(), $tagarr = array())
{
if (empty($tid)) return '';
// 新标签处理入库
if ($new_tags) {
$threadarr = array();
$tagids = array();
$i = 0;
$size = 5;
$n = count($tagarr);
$n = $n > $size ? $size : $size - $n;
foreach ($new_tags as $name) {
++$i;
$name = trim($name);
$name = stripslashes($name);
$name = strip_tags($name);
$name = str_replace(array(' ', '#', "@", "$", "%", "^", '&', '·', '<', '>', ';', '`', '~', '!', '¥', '……', ';', '?', '?', '-', '—', '_', '=', '+', '.', '{', '}', '|', ':', ':', '、', '/', '。', '[', ']', '【', '】', '‘', ' ', ' ', ' ', ' ', ' '), '', $name);
$name = htmlspecialchars($name, ENT_QUOTES);
if ($name && $i <= $n) {
// 查询标签
$read = well_tag_read_name($name);
if ($read) {
// 存在 count+1
$tagids[] = $read['tagid'];
} else {
// 入库
$arr = array('name' => $name, 'count' => 1);
$tagid = well_tag_create($arr);
FALSE === $tagid and message(-1, lang('create_failed'));
$read = array('tagid' => $tagid, 'name' => $name);
}
$tag_thread = array('tagid' => $read['tagid'], 'tid' => $tid);
$threadarr[] = $tag_thread;
$tagarr[$read['tagid']] = $read['name'];
}
}
!empty($threadarr) and tag_thread_big_insert($threadarr);
!empty($tagids) and well_tag_update($tagids, array('count+' => 1));
}
$json = empty($tagarr) ? '' : xn_json_encode($tagarr);
return $json;
}
?> $v = implode(",", $v);
$temp[] = $v;
}
// 去掉重复的字符串,也就是重复的一维数组
$temp = array_unique($temp);
// 再将拆开的数组重新组装
$output = array();
foreach ($temp as $k => $v) {
if ($stkeep) $k = $starr[$k];
if ($ndformat) {
$temparr = explode(",", $v);
foreach ($temparr as $ndkey => $ndval) $output[$k][$ndarr[$ndkey]] = $ndval;
} else $output[$k] = explode(",", $v);
}
return $output;
}
// 合并二维数组 如重复 值以第一个数组值为准
function array2_merge($array1, $array2, $key = '')
{
if (empty($array1) || empty($array2)) return NULL;
$arr = array();
foreach ($array1 as $k => $v) {
isset($v[$key]) ? $arr[$v[$key]] = array_merge($v, $array2[$k]) : $arr[] = array_merge($v, $array2[$k]);
}
return $arr;
}
/*
* 对二维数组排序 两个数组必须有一个相同的键值
* $array1 需要排序数组
* $array2 按照该数组key排序
* */
function array2_sort_key($array1, $array2, $key = '')
{
if (empty($array1) || empty($array2)) return NULL;
$arr = array();
foreach ($array2 as $k => $v) {
if (isset($v[$key]) && $v[$key] == $array1[$v[$key]][$key]) {
$arr[$v[$key]] = $array1[$v[$key]];
} else {
$arr[] = $v;
}
}
return $arr;
}
?>
windows10 通过bat脚本安装软件编程频道|福州电脑网
windows10 通过bat脚本安装软件
编程之家760
更新时间:2026-04-03 20:25:57
通过bat脚本安装软件
最近公司需要对外开源一个产品,为了让外界用户尽量简单的使用该产品。打算将依赖软件采用一个脚本的方式进行快速安装。
脚本编写
这里安装的软件包括:docker, vcxsrv, nodejs 及 使用npm安装adbkit
:: 将
@echo off
:: 设置窗口大小
@mode con lines=40 cols=100
:: 设置窗口背景颜色
color AF
:: 设置标题
title "auto install tool"
:: 打印信息
echo "install begin .....">log.txt
:: docker
echo.
echo docker install ......
:: wait 参数表示需要等上一个软件安装之后再进行一个软件安装,因为有时候需要依赖前一个软件,所以这个功能很有用,比如安装adbkit需要先安装nodejs,然后使用nodejs的npm安装adbkit
start /wait .\Docker_Desktop_Installer.exe
:: 根据打印日志的级别判断是否安装成功并答应相应的信息
if %errorlevel% == 0 (echo docker install successful) else echo docker install failed
:: vcxsrv
echo.
echo vcxsrv install ......
start /wait .\vcxsrv-64.1.20.8.1.installer.exe
if %errorlevel% == 0 (echo vcxsrv install successful) else echo vcxsrv install failed
:: nodejs
echo.
echo nodejs install ......
:: 这里安装msi文件
start /wait .\node-v14.15.0-x64.msi /l*v log.txt
if %errorlevel% == 0 (echo nodejs install successful) else echo nodejs install failed
:: adbkit
echo adbkit install ......
npm install i -g adbkit
if %errorlevel% == 0 (echo adbkit install successful) else echo adbkit install failed
echo "install finished">log.txt
pause
碰到的问题
1. Q:安装包的路径被截断,提示安装失败
A:安装包路径中不要出现空格,否则识别会出错。 windows的脚本挺坑的
2. Q:安装nodejs之后,在使用npm安装adbkit时提示无法识别npm命令
A: 安装adbkit是依赖前面安装的nodejs,而开启当前终端时是没有配置nodejs的环境变量的,即使通过当前安装脚本重新代开一个终端执行npm命令也不行,因为在当前bat脚本中打开终端属于子进程,不会去加载环境变量。解决方案时,安装完nodejs之后,在写一个使用npm安装adbkit的脚本单独运行。
4.
其他常见操作汇总
1. 查看环境变量
set
2. 设置系统环境变量
set PATH = %PATH%;C:\Program Files\nodejs\node_modules\npm
3. 调用其他bat文件
start install_adbkit.bat :: 或
@call install_adbkit.bat
4. 从C盘切换到D盘目录
d: :: 先到D盘
cd d:\you\file\directory
5. 获取执行命令的返回值
:: 先通过adb devices获取设备序列好,然后将该值用于adbkit的输入
for /F %%i in ('adb devices') do ( set adb_device=%%i)
echo detect phone deviceid=%adb_device%
start /b adbkit usb-device-to-tcp -p 7788 %adb_device%
6. 查看进程信息
:: 列举当前的进程、进程路径、命令行、进程ID、父进程ID、线程数,内存使用
wmic process get name,executablepath,commandline,processid,parentprocessid,threadcount,workingsetsize/value
:: 查询可用属性 : processid,caption,commandline
wmic process get /?
:: /value显示对应列表
wmic process get caption,commandline /value
:: 根据caption查询进程信息
wmic process where caption="update.exe" get processid,caption,commandline /value
参考文献
http://www.360doc/content/19/1007/14/10519289_865323566.shtml
https://blog.csdn/WannaHaha/article/details/106289435
http://www.360doc/content/13/0311/20/1865135_270860611.shtml
https://stackoverrun/cn/q/6918426
本文发布于:2025-08-09,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本软件bat
发布评论