Running shell script only if parallel backgrounded scripts complete successfully
By : jenifer
Date : March 29 2020, 07:55 AM
should help you out I have 4 bash scripts: , You can use warpper.sh like this: code :
#!/bin/bash
# execute script1.sh in background and save pid in $pid1
./script1.sh &
pid1=$!
# execute script2.sh in background and save pid in $pid2
./script2.sh &
pid2=$!
# do more work here...
# wait for both background jobs to finish and save their return status
wait $pid1 && wait $pid2 && ./script3.sh
|
Using inotifywait (or alternative) to wait for rsync transfer to complete before running script?
By : Santhosh M
Date : March 29 2020, 07:55 AM
should help you out Depending on what action you want to take, you may want to take a look at the tools provided by Watchman. There are two that might be most useful to you:
|
Why xrange is not defined when I'm not using xrange in the first place?
By : Amish S. Dave
Date : November 20 2020, 03:01 PM
wish of those help You are running stale bytecode, restart Python. Python compiles source code to bytecode, and interprets the latter. This means the interpreter doesn't work with the source code once compiled.
|
NameError: name 'xrange' is not defined when running tensorflow object detection api
By : Ranjeet Kumar
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , xrange() was removed from python3 and was replaced by range(). Use range() instead (it works exactly the same as xrange()). However, if you need to use the range() function in python2 (which you don't in this case), use xrange() as range() returns a list instead of a generator (as @xdurch0 says in the comments).
|
Running a complete powershell script from within C#
By : user3511243
Date : March 29 2020, 07:55 AM
seems to work fine The below solution is quite different from the PowerShell snippet that you posted. Overview: The Functionality is present in Class PinToTaskBar And Invoked from Class Program code :
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Management.Automation;
using System.Text;
namespace ConfiguratorLibrary
{
public class PinToTaskBar
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern IntPtr LoadLibrary(string lpLibFileName);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern int LoadString(IntPtr hInstance, uint wID, StringBuilder lpBuffer, int nBufferMax);
public static bool PinUnpinTaskbar(string filePath, bool pin)
{
if (!File.Exists(filePath)) throw new FileNotFoundException(filePath);
int MAX_PATH = 255;
var actionIndex = pin ? 5386 : 5387; // 5386 is the DLL index for"Pin to Tas&kbar", ref. win7dll.info/shell32_dll.html
//uncomment the following line to pin to start instead
//actionIndex = pin ? 51201 : 51394;
StringBuilder szPinToStartLocalized = new StringBuilder(MAX_PATH);
IntPtr hShell32 = LoadLibrary("Shell32.dll");
LoadString(hShell32, (uint)actionIndex, szPinToStartLocalized, MAX_PATH);
string localizedVerb = szPinToStartLocalized.ToString();
string path = Path.GetDirectoryName(filePath);
string fileName = Path.GetFileName(filePath);
// create the shell application object
dynamic shellApplication = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"));
dynamic directory = shellApplication.NameSpace(path);
dynamic link = directory.ParseName(fileName);
dynamic verbs = link.Verbs();
for (int i = 0; i < verbs.Count(); i++)
{
dynamic verb = verbs.Item(i);
if (verb.Name.Equals(localizedVerb))
{
verb.DoIt();
return true;
}
}
return false;
}
static string originalImagePathName;
static int unicodeSize = IntPtr.Size * 2;
static void GetPointers(out IntPtr imageOffset, out IntPtr imageBuffer)
{
IntPtr pebBaseAddress = GetBasicInformation().PebBaseAddress;
var processParameters = Marshal.ReadIntPtr(pebBaseAddress, 4 * IntPtr.Size);
imageOffset = processParameters.Increment(4 * 4 + 5 * IntPtr.Size + unicodeSize + IntPtr.Size + unicodeSize);
imageBuffer = Marshal.ReadIntPtr(imageOffset, IntPtr.Size);
}
internal static void ChangeImagePathName(string newFileName)
{
IntPtr imageOffset, imageBuffer;
GetPointers(out imageOffset, out imageBuffer);
//Read original data
var imageLen = Marshal.ReadInt16(imageOffset);
originalImagePathName = Marshal.PtrToStringUni(imageBuffer, imageLen / 2);
var newImagePathName = Path.Combine(Path.GetDirectoryName(originalImagePathName), newFileName);
if (newImagePathName.Length > originalImagePathName.Length) throw new Exception("new ImagePathName cannot be longer than the original one");
//Write the string, char by char
var ptr = imageBuffer;
foreach(var unicodeChar in newImagePathName)
{
Marshal.WriteInt16(ptr, unicodeChar);
ptr = ptr.Increment(2);
}
Marshal.WriteInt16(ptr, 0);
//Write the new length
Marshal.WriteInt16(imageOffset, (short) (newImagePathName.Length * 2));
}
internal static void RestoreImagePathName()
{
IntPtr imageOffset, ptr;
GetPointers(out imageOffset, out ptr);
foreach (var unicodeChar in originalImagePathName)
{
Marshal.WriteInt16(ptr, unicodeChar);
ptr = ptr.Increment(2);
}
Marshal.WriteInt16(ptr, 0);
Marshal.WriteInt16(imageOffset, (short)(originalImagePathName.Length * 2));
}
public static ProcessBasicInformation GetBasicInformation()
{
uint status;
ProcessBasicInformation pbi;
int retLen;
var handle = System.Diagnostics.Process.GetCurrentProcess().Handle;
if ((status = NtQueryInformationProcess(handle, 0,
out pbi, Marshal.SizeOf(typeof(ProcessBasicInformation)), out retLen)) >= 0xc0000000)
throw new Exception("Windows exception. status=" + status);
return pbi;
}
[DllImport("ntdll.dll")]
public static extern uint NtQueryInformationProcess(
[In] IntPtr ProcessHandle,
[In] int ProcessInformationClass,
[Out] out ProcessBasicInformation ProcessInformation,
[In] int ProcessInformationLength,
[Out] [Optional] out int ReturnLength
);
public static IntPtr Increment(this IntPtr ptr, int value)
{
unchecked
{
if (IntPtr.Size == sizeof(Int32))
return new IntPtr(ptr.ToInt32() + value);
else
return new IntPtr(ptr.ToInt64() + value);
}
}
[StructLayout(LayoutKind.Sequential)]
public struct ProcessBasicInformation
{
public uint ExitStatus;
public IntPtr PebBaseAddress;
public IntPtr AffinityMask;
public int BasePriority;
public IntPtr UniqueProcessId;
public IntPtr InheritedFromUniqueProcessId;
}
}
class TestClass
{
static void Main(string[] args)
{
var pin = new PinToTaskBar();
try
{
pin.ChangeImagePathName("explorer.exe");
pin.PinUnpinTaskbar(tempFilePath, true);
}
Catch(Exception ex)
{
Console.WriteLine(ex.Message + ex.InnerException);
}
finally
{
pin.RestoreImagePathName();
}
}
}
}
|